Post by trail_frog
I'm using EnumWindows() function in my application to help identify open
windows. Inside of my EnumWindowsProc() implementation, I monitor which
windows are open and which applications these windows belong to. It's
used for a feature similar to screen capture.
Whenever there is a context menu open, my application can't identify
which window/application it belongs to. The context menu has window
style WS_EX_TOOLWINDOW and class name "#32768".
For example, if I have InternetExplorer open and I right click on that IE
window, I want to have some code in my EnumWindowsProc() implementation
that can identify that the context menu is related to the IE window. In
other words, I want to detect that the IE window is the window that was
right-clicked in order for that context menu to be opened.
Does anyone know if this is possible?
I don't think it's possible. Any application can have more than one main
windows, or none.
The only thing I could think of is to find all of the top level windows
which aren't owned by other window (via GetWindow() with GW_OWNER). i.e.
first find out the prosess ID the popup menu is using
GetWindowThreadProcessId(), then enumerate the process' windows using
EnumWindows and filter them out based on their process ID and owner.
For MSIE, I think the above method can be used. Also, since newer MSIE uses
multi-process, you might end up with the process ID of the MSIE's
sub-process. So in this case, you'll need to get the main process using
NtQueryInformationProcess(). The parent process ID is the Reserved3 field of
the PROCESS_BASIC_INFORMATION structure.