Gianni Posted August 9, 2015 Share Posted August 9, 2015 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 miserablyevidently 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)) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
water Posted August 9, 2015 Share Posted August 9, 2015 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 More sharing options...
mikell Posted August 9, 2015 Share Posted August 9, 2015 Works onLocal $hChild = GUICreate("Child GUI", 250, 150, 10, 10, $WS_CHILD, -1, $hParent)but it seems a weak usefulness... Link to comment Share on other sites More sharing options...
Gianni Posted August 9, 2015 Author Share Posted August 9, 2015 @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)) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
KaFu Posted August 9, 2015 Share Posted August 9, 2015 (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 August 9, 2015 by KaFu Gianni 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Gianni Posted August 9, 2015 Author Share Posted August 9, 2015 (edited) @KaFu ThanksIt 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 August 9, 2015 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now