Discussion:
How to find main window related to context menu window
(too old to reply)
trail_frog
2017-12-28 01:23:52 UTC
Permalink
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?

Thanks.
R.Wieser
2017-12-28 07:58:11 UTC
Permalink
trail_frog,
Post by trail_frog
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'm not sure if it is what you need, but it could not hurt to take a look at
GWL_HWNDPARENT (GetWindowLong).

Regards,
Rudy Wieser
JJ
2017-12-28 17:36:18 UTC
Permalink
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?
Thanks.
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.
Christian Astor
2017-12-28 20:05:17 UTC
Permalink
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?
You can do :
GetWindowThreadProcessId()
OpenProcess()
QueryFullProcessImageName()

Loading...