Is it possible for 2 windows managed by Windows to have the same window handle value?
Consider both cases when these 2 windows are opened by the same process and when these 2 windows are opened by 2 different processes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quick answer: no, it’s not possible if they are inside the same desktop, every window handle issued by the window manager is unique (inside its desktop) throughout all the existence of the window, otherwise it couldn’t uniquely identify such window on the
systemcurrentwindow stationdesktop (which is defined by MSDN as “a logical display surface” that “contains user interface objects such as windows, menus, and hooks; it can be used to create and manage windows”).Long answer:
The issue is discussed here, which points to this article. It seems that
HWNDs are local to desktops , so you can have two identicalHWNDs that point to two different windows, but they are necessarily in two separated desktops, so there’s no ambiguity (the WM handle you pass to every user32 function refers implicitly to the current desktop, to go to another one you have to useSetThreadDesktop, and this call fails if your thread owns any desktop-contained object into the current desktop).On the other hand, when a window is destroyed, its handle can be reused, but IIRC the window manager employs some techniques to avoid immediately reusing a handle.