Page 1 of 1

Help Making IsChild DllCall Work

Posted: 22 Sep 2022, 13:01
by xavier
I need help to make this code work
All tests throw a "Is Not Child" result even when opening a Find window in Notepad++ which (I believe) is a child window of the Notepad++ main window
Any thoughts?

Code: Select all

GroupAdd, HotGrp, ahk_exe Notepad++.exe

IsChildWindow(Parent, WinHnd) {
	Local DllRes
	DllRes:= DllCall("IsChild", "Ptr", Parent, "Ptr", WinHnd)
	If (ErrorLevel <> 0) {
		Msgbox, 64, Dll Call Error, % "Error Level: " . ErrorLevel
	}
	Return DllRes
}

WinWaitActive, ahk_group HotGrp
WinGet, ActHnd, ID, A
WinGetActiveTitle, ActTit
Loop {
	WinWaitNotActive, ahk_id %ActHnd%
	OldHnd:= ActHnd
	OldTit:= ActTit
	WinWaitActive, ahk_group HotGrp
	WinGet, ActHnd, ID, A
	WinGetActiveTitle, ActTit
	If IsChildWindow(OldHnd, ActHnd) {
		ChildIs:= ActHnd
	} Else ChildIs:= 0
	MsgBox, 64, % "Is " . (ChildIs = 0 ? "Not " : "") . "Child", % "Window [" . ActTit . "] Is " . (ChildIs = 0 ? "Not " : "") . "Child Of [" . OldTit . "]"
}

Re: Help Making IsChild DllCall Work

Posted: 25 Sep 2022, 12:06
by safetycar
It's possible that it is not a child window, but you might get what you need comparing the ProcessIds (PID) of each window and if they are the same do your action. Check WinGet.

Re: Help Making IsChild DllCall Work

Posted: 26 Sep 2022, 03:18
by just me
The 'Find' window is most probably a dialog window which may be owned by the main window but rather not be a (direct) child of it.