Get belonging hwnd?

Windows specific forum
jacky
User
User
Posts: 63
Joined: Mon Jan 21, 2019 1:41 pm

Get belonging hwnd?

Post 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
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Get belonging hwnd?

Post 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)
jacky
User
User
Posts: 63
Joined: Mon Jan 21, 2019 1:41 pm

Re: Get belonging hwnd?

Post 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)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Get belonging hwnd?

Post by Mijikai »

For the 'root' window u can also try one of these Apis:

Code: Select all

;GetWindow_() -> with #GW_OWNER
;GetPartent_()
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Get belonging hwnd?

Post 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_()
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Get belonging hwnd?

Post by Mijikai »

Bisonte wrote: A typo ;)
:mrgreen:
jacky
User
User
Posts: 63
Joined: Mon Jan 21, 2019 1:41 pm

Re: Get belonging hwnd?

Post by jacky »

Thanks Mijikai,

Code: Select all

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