ListBox left click problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

ListBox left click problem

12 Dec 2020, 13:56

I have a simple ListBox where the item can be selected with a mouse click. This works well.
In addition I wanted to add that clicking outside the window would close it. I tried the script below (commented part) but it doesn't work.
What am I doing wrong? Thanks.

Code: Select all

gui, font, s10
gui, add, ListBox, w200 r6 vOut gComplete, A|B|C|D
hWindow := WinExist()
gui, show,, MyWin
return

Complete:
If (A_GuiEvent != "" && A_GuiEvent != "Normal")
    Return
GuiControlGet, Index,, Out
msgbox % Index
return

;~ #IfWinExist MyWin ahk_class AutoHotkeyGUI
;~ ~LButton::
;~ MouseGetPos,,, Temp1
;~ If (Temp1 != hWindow)
    ;~ Gui, Hide
;~ Return
;~ #IfWinExist
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: ListBox left click problem

12 Dec 2020, 14:20

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
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: ListBox left click problem

12 Dec 2020, 15:03

Thanks, great learning. :)

The first example works. I will have other guis so probably this will not be the best.
The Msgbox was a bad example, in the final code this will be a different code. Nevertheless, the second example is great!
I'm not sure about the third one, is this an alternative for the second one?
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: ListBox left click problem

12 Dec 2020, 15:10

Yes, they are just variations. The third one would still need to fix the hWindow issue. The MsgBox is a dialog box with class #32770, so that is what you are seeing there-- a way to bypass the routine if the MsgBox exists.

Enjoy!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ht55cd3 and 263 guests