This function does not open windows!5ball wrote:.. and sometimes open more windows than requested.
Which AHK_H version are you using, do you have some example code.
This function does not open windows!5ball wrote:.. and sometimes open more windows than requested.
Code: Select all
Gui, Add, Text, vCO w120 center, %CurrentlyOpen%
Gui, show, w150 h30
KeepOpen = 100
CurrentlyOpen = 0
Loop
{
WinGet, CurrentlyOpen, Count, Untitled - Notepad
GuiControl, , CO, %CurrentlyOpen%
If (CurrentlyOpen < KeepOpen)
{
Run notepad.exe
WinWaitCreated("Untitled - Notepad")
}
}
return
GuiClose:
exitapp
return
/*
Wait for a window to be created, returns 0 on timeout and ahk_id
otherwise
Parameter are the same as WinWait, see
http://ahkscript.org/docs/commands/WinWait.htm
Forum: http://ahkscript.org/boards/viewtopic.php?
f=6&t=1274&p=8517#p8517
*/
WinWaitCreated( WinTitle:="", WinText:="", Seconds:=0,
ExcludeTitle:="", ExcludeText:="" ) {
; HotKeyIt - http://ahkscript.org/boards/viewtopic.php?t=1274
static Found := 0, _WinTitle, _WinText, _ExcludeTitle, _ExcludeText
, init := DllCall( "RegisterShellHookWindow", "UInt",A_ScriptHwnd )
, MsgNum := DllCall( "RegisterWindowMessage",
"Str","SHELLHOOK" )
, cleanup:={base:{__Delete:"WinWaitCreated"}}
If IsObject(WinTitle) ; cleanup
return DllCall("DeregisterShellHookWindow","PTR",A_ScriptHwnd)
else if (Seconds <> MsgNum){ ; User called the function
Start := A_TickCount, _WinTitle := WinTitle, _WinText := WinText
,_ExcludeTitle := ExcludeTitle, _ExcludeText := ExcludeText
,OnMessage( MsgNum, A_ThisFunc ), Found := 0
While ( !Found && ( !Seconds || Seconds * 1000 < A_TickCount -
Start ) )
Sleep 16
Return Found,OnMessage( MsgNum, "" )
}
If ( WinTitle = 1 ; window created, check if it is our window
&& ExcludeTitle = A_ScriptHwnd
&& WinExist( _WinTitle " ahk_id "
WinText,_WinText,_ExcludeTitle,_ExcludeText))
WinWait % "ahk_id " Found := WinText ; wait for window to be shown
}
Code: Select all
SetBatchLines, -1
Gui, +AlwaysOnTop
Gui, Add, Text, vCO w120 center, %CurrentlyOpen%
Gui, show, w150 h30
KeepOpen = 100
CurrentlyOpen = 0
Loop
{
WinGet, CurrentlyOpen, Count, Untitled - Notepad
GuiControl, , CO, %CurrentlyOpen%
If (CurrentlyOpen < KeepOpen)
{
DynaRun("Sleep 10`nRun notepad.exe") ; run notepad in a different process so WinWaitCreated has a chance to receive the message!
WinWaitCreated("Untitled - Notepad")
}
else break
}
return
GuiClose:
Loop {
Process,Exist,notepad.exe
If !Errorlevel
break
Process, Close, %ErrorLevel%
}
ExitApp
yesevilC wrote:Are there any techniques in this code that could be used to detect change of active window without needing a WinExist("A") loop?
I figured that might be the issue, and it turns out it isn't a problem for my application.HotKeyIt wrote:The problem is that the window is created before we start waiting for it!
Code: Select all
Hwnd := WinWaitCreated("ahk_exe gimp-2.10.exe")
Return to “Scripts and Functions (v1)”
Users browsing this forum: nitsik and 168 guests