I have a program I run that uses a lot of pop up message and I want to automatically detect them and press a given button on them. I have it working using a hotkey. For example, one of the popups has the word Confirm in its title. Using the hot key, I can close it with this.
IfWinExist, Confirm
{
WinActivate
Click, 212, 136
return
}
However, I want to do this without using a hotkey; just want to detect the new window when it's opened and have it done automatically. I've read through this thread:
<!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=16&t=86496">viewtopic.php?f=16&t=86496</a><!-- l -->
However, it seems this doesn't work for child windows. Anyone know how to detect child windows when they pop up?
Thanks.

Detecting New Child Window
Started by
QTipPoker
, Sep 26 2012 02:49 PM
5 replies to this topic
#1
-
Posted 26 September 2012 - 02:49 PM

I can't speak to using shell messages.
But what about using 'Settimer' to run the lines you listed ?
And I suggest moving the return outside the {}
Btw, please post your script within [code] [/code] tags
But what about using 'Settimer' to run the lines you listed ?
And I suggest moving the return outside the {}
Btw, please post your script within [code] [/code] tags
#2
-
Posted 26 September 2012 - 10:33 PM

Thanks a lot. I do have that worked out, but I was concerned it might slow down the rest of my code or use a lot of processing to have it check like every 250 milliseconds. So I thought I would try to do it only when necessary...maybe I'm overestimating the stress it puts on a system.
That return thing...things are muddy for me with this return. I've read through the tutorials and see you need one when you have more than one line in a code, but then other times in a tutorial I see it used after only one line.
That return thing...things are muddy for me with this return. I've read through the tutorials and see you need one when you have more than one line in a code, but then other times in a tutorial I see it used after only one line.
#3
-
Posted 27 September 2012 - 12:46 AM

Return is so important, it was given its own page in the helpfile.
Here it is in the on-line docs <!-- m -->http://www.autohotke...ands/Return.htm<!-- m -->
In the case of your example, perhaps this will help explain.
Concerning the stress on the system, I suggest searching for the variable 'A_TickCount' in the docs and looking at the related 'elapsedtime' example. Remove the
and place the remaining lines around one of your long loops, to see how long it actually takes.
Maybe this will give you a feel for the time things take to accomplish.
Another method is to try the following in your script.
Here it is in the on-line docs <!-- m -->http://www.autohotke...ands/Return.htm<!-- m -->
In the case of your example, perhaps this will help explain.
IfWinExist, Confirm { WinActivate Click, 212, 136 return } Msgbox oops the Confirm windows didn't exist
Concerning the stress on the system, I suggest searching for the variable 'A_TickCount' in the docs and looking at the related 'elapsedtime' example. Remove the
sleep, 1000
and place the remaining lines around one of your long loops, to see how long it actually takes.
Maybe this will give you a feel for the time things take to accomplish.
Another method is to try the following in your script.
settimer, counter, 250 return counter: count++ tooltip % count return
#4
-
Posted 27 September 2012 - 01:59 AM

Here's an example that sets a hook for the child window - requires AutoHotkey_L & the Acc Library. Press F1 to create the Child Window:
EVENT_OBJECT_CREATE := "0x8000" Gui, New, HWNDGuiHwnd Gui, Show, w150 h50 pCallback := RegisterCallback("WinEventProc") Acc_SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, pCallBack) return GuiClose: Acc_UnhookWinEvent(pCallback) ExitApp F1:: Gui %GuiHwnd%: Add, Text, x10 y10 w80 h20, Hello World! WinEventProc(hHook, event, hWnd, idObject, idChild, eventThread, eventTime) { global GuiHwnd Acc := Acc_ObjectFromEvent(_idChild_, hWnd, idObject, idChild) if Acc.accRole(0)=9 and DllCall("GetParent", "Ptr",hwnd)=GuiHwnd MsgBox, , New Child Win, % "ClassNN: " GetClassNN(hWnd,GuiHwnd) } GetClassNN(Chwnd, Whwnd) { global _GetClassNN := {} _GetClassNN.Hwnd := Chwnd Detect := A_DetectHiddenWindows WinGetClass, Class, ahk_id %Chwnd% _GetClassNN.Class := Class DetectHiddenWindows, On EnumAddress := RegisterCallback("GetClassNN_EnumChildProc") DllCall("EnumChildWindows", "uint",Whwnd, "uint",EnumAddress) DetectHiddenWindows, %Detect% return, _GetClassNN.ClassNN, _GetClassNN:="" } GetClassNN_EnumChildProc(hwnd, lparam) { static N global _GetClassNN WinGetClass, Class, ahk_id %hwnd% if _GetClassNN.Class == Class N++ return _GetClassNN.Hwnd==hwnd? (0, _GetClassNN.ClassNN:=_GetClassNN.Class N, N:=0):1 }
#6
-
Posted 27 September 2012 - 07:25 AM
