Jump to content

how to use the _WinAPI_IsChild function?


Recommended Posts

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))

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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))

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

:)

@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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...