Chimp

how to use the _WinAPI_IsChild function?

6 posts in this topic

According to the _WinAPI_IsChild() documentation, this function should return true if a window is child of another window,
here is my try to test if this is true, but I failed miserably
evidently this is not a "foolproof" function....
could someone smarter than me give a hint on how to use it?
thanks

#include <WinAPISys.au3>

Local $hParent = GUICreate("Main GUI")
GUISetState(@SW_SHOW, $hParent)
;
Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10)
GUISetState(@SW_SHOW, $hChild)
;
_WinAPI_SetParent($hChild, $hParent)

MsgBox(0, "Is child?", _WinAPI_IsChild($hChild, $hParent))

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



Found a working example here.
Strange enough it only returns True when checking a Control.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Works on

Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10, $WS_CHILD, -1, $hParent)

but it seems a weak usefulness...

Share this post


Link to post
Share on other sites

@water, thanks, I have seen there that it works with child controls..., but I need to check child windows (weird behavior of this function)

@mikell thanks, but if I use $WS_CHILD the function seems to work, but unfortunately the child window will disappear....

#include <WindowsConstants.au3>
#include <WinAPISys.au3>

Local $hParent = GUICreate("Main GUI")
GUISetState(@SW_SHOW, $hParent)
;
Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10, $WS_CHILD, -1, $hParent)
GUISetState(@SW_SHOW, $hChild)
;
_WinAPI_SetParent($hChild, $hParent)

MsgBox(0, "Is child?", _WinAPI_IsChild($hChild, $hParent))

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

That brought me to this completely unnecessary UDF ^_^...

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hParent = GUICreate("Main GUI")
Local $c_Button_0 = GUICtrlCreateButton("Button0", 10, 10)
GUISetState(@SW_SHOW, $hParent)

Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10)
Local $c_Button_1 = GUICtrlCreateButton("Button1", 10, 10)
GUISetState(@SW_SHOW, $hChild)
_WinAPI_SetParent($hChild, $hParent)

Local $hChild2 = GUICreate("Child GUI", 250, 150, 10, 10)
Local $c_Button_2 = GUICtrlCreateButton("Button2", 10, 10)
GUISetState(@SW_SHOW, $hChild2)
_WinAPI_SetParent($hChild2, $hChild)

MsgBox(0, "_Window_NestingDepth", _Window_NestingDepth($hParent) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_0)) & @CRLF & @CRLF _
         & _Window_NestingDepth($hChild) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_1)) & @CRLF & @CRLF _
         & _Window_NestingDepth($hChild2) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_2)))

Func _Window_NestingDepth($hWnd)
    Local $hWnd_Desktop = _WinAPI_GetDesktopWindow(), $hWnd_Parent = _WinAPI_GetAncestor($hWnd, $GA_PARENT)
    If $hWnd_Parent = $hWnd_Desktop Then Return 0 ; Parent is Desktop
    Local $iEnum = 0
    While 1
        If $hWnd_Parent = $hWnd_Desktop Then Return $iEnum
        $iEnum += 1
        If $iEnum = 999 Then Return 999
        $hWnd_Parent = _WinAPI_GetAncestor($hWnd_Parent, $GA_PARENT)
    WEnd
EndFunc   ;==>_Window_NestingDepth

 

Edited by KaFu
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

:)

@KaFu Thanks

It seems to me that your function returns true if the passed window is a child window (but it doesn't says who is the father)  and it also returns the depth that this child window is nested.
what I need is to know if a given window is the child of a known father,
well, the _WinAPI_GetAncestor function  that you used in your udf can be of use for my purpose in this way:

#include <WindowsConstants.au3>
#include <WinAPISys.au3>

Local $hParent = GUICreate("Main GUI")
GUISetState(@SW_SHOW, $hParent)
;
Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10)
GUISetState(@SW_SHOW, $hChild)
;
_WinAPI_SetParent($hChild, $hParent)

MsgBox(0, "Is child?", $hParent = _WinAPI_GetAncestor($hChild))

Thanks a lot!

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now