MsgBox is a different window, so if you click on it, your condition is met.
Your hWindow is null because the window is visible only after
Show. The second example below shows an easier method using
Gui, +Hwnd....
Code: Select all
#IfWinExist MyWin ahk_class AutoHotkeyGUI ahk_exe AutoHotkey.exe
~LButton::
WinGet, proc, ProcessName, A
If (proc = "AutoHotkey.exe")
Return
SoundBeep, 1500, 20
Gui, Hide
Return
#IfWinExist
Or:
Code: Select all
wTitle = MyWin
Gui, +Hwnduid
gui, font, s10
gui, add, ListBox, w200 r6 vOut gComplete, A|B|C|D
gui, show,, %wTitle%
Return
Complete:
If (A_GuiEvent != "" && A_GuiEvent != "Normal")
Return
GuiControlGet, Index,, Out
wait := True
msgbox % Index
wait := False
return
#IfWinExist MyWin ahk_class AutoHotkeyGUI ahk_exe AutoHotkey.exe
~LButton::
If wait
Return
MouseGetPos,,, thisUID
If (thisUID = uid)
Return
SoundBeep, 1500, 20
Gui, Hide
Return
#IfWinExist
Or:
Code: Select all
#IfWinExist MyWin ahk_class AutoHotkeyGUI ahk_exe AutoHotkey.exe
~LButton::
If WinExist("ahk_class #32770 ahk_exe AutoHotkey.exe")
Return
MouseGetPos,,, thisUID
If (thisUID = hWindow)
Return
SoundBeep, 1500, 20
Gui, Hide
Return
#IfWinExist