Page 1 of 1

Get belonging hwnd?

Posted: Fri Feb 22, 2019 8:22 pm
by jacky
Hi,

As an example: Let's say you open Windows Explorer and from within its "Folder options" window.

Two questions:
01. The folder options window contains a few tabs and subsections with elements.
How do I get the hwnd of this window when the mouse is hovering over any element in this window?

02. How do I get the hwnd of the "root" window (the hwnd of the belonging Windows Explorer window) under the same assumption that the mouse is over any element in the folder options window?

Or more generalized:
How should this be done for any application (finding the hwnd of the window that the current hovered element belongs to and finding the hwnd of the main (if the current window is a child window) window)?

Tia,
Jacky

Re: Get belonging hwnd?

Posted: Sat Feb 23, 2019 12:03 am
by Mijikai
Try this :)

Get hwnd from mouse pos:

Code: Select all

p.q
GetCursorPos_(@p);
Debug WindowFromPoint_(p)
Get root:

Code: Select all

GetAncestor_(hwnd,#GA_ROOT)

Re: Get belonging hwnd?

Posted: Sat Feb 23, 2019 9:12 am
by jacky
Thank you, Mijikai!
Get hwnd from mouse pos
This works fine.
GetAncestor_(hwnd,#GA_ROOT)
This doesn't get me the hwnd of the window that the (sub) window belongs too.

E.g. if the folder options window is open and the mouse is inside of it, it returns
the hwnd of that folder options window and not the hwnd of the window it "belongs too" (the main Windows Explorer window)

Re: Get belonging hwnd?

Posted: Sat Feb 23, 2019 11:50 am
by Mijikai
For the 'root' window u can also try one of these Apis:

Code: Select all

;GetWindow_() -> with #GW_OWNER
;GetPartent_()

Re: Get belonging hwnd?

Posted: Sat Feb 23, 2019 8:50 pm
by Bisonte
Mijikai wrote:For the 'root' window u can also try one of these Apis:

Code: Select all

;GetWindow_() -> with #GW_OWNER
;GetPartent_()
A typo ;)

Code: Select all

GetParent_()

Re: Get belonging hwnd?

Posted: Sat Feb 23, 2019 9:04 pm
by Mijikai
Bisonte wrote: A typo ;)
:mrgreen:

Re: Get belonging hwnd?

Posted: Tue Feb 26, 2019 7:13 am
by jacky
Thanks Mijikai,

Code: Select all

GetWindow_() -> with #GW_OWNER
is what I was looking for :D