Help Making IsChild DllCall Work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xavier
Posts: 6
Joined: 25 May 2022, 18:20

Help Making IsChild DllCall Work

Post by xavier » 22 Sep 2022, 13:01

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 . "]"
}

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Help Making IsChild DllCall Work

Post by safetycar » 25 Sep 2022, 12:06

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.

just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Help Making IsChild DllCall Work

Post by just me » 26 Sep 2022, 03:18

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.

Post Reply

Return to “Ask for Help (v1)”