 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TheGood
Joined: 30 Jul 2007 Posts: 516
|
Posted: Sun Dec 28, 2008 7:59 pm Post subject: How to detect doubleclicks in ListBox |
|
|
Although it is possible to check for a ListBox's doubleclick event by setting a g-label and checking A_GuiEvent for "DoubleClick", the method isn't fully reliable. There are two shortcomings (not due to AHK, but due to the fact that doubleclick events in ListBoxes rely on the LBN_DBLCLK notification which purposely lacks those features):
1 - If there are no items in the ListBox, no event will be fired upon doubleclicking
2 - If an item is already selected in the ListBox, there are no distinctions between clicking on the item, and off of it (in an empty area)
I made a little script that allows you to make those distinctions.
How to use/add to your code
You need to set the handle variable when creating the ListBox (by adding the option hwnd[name of variable] when using Gui, Add). You also need to add OnMessage(515, "OnDblClick"). And finally, you need the whole function OnDblClick from the script below (as well as setting up the labels to call for each possibility).
| Code: | Gui, Add, ListBox, hwndhLB, This is a listbox item
OnMessage(515, "OnDblClick") ;Intercept WM_LBUTTONDBLCLK notifications
Gui, Show
Return
GuiClose:
ExitApp
OnDblClick(wParam, lParam, msg, hwnd) {
;Make the var global so that we can access it
Global hLB
;Make sure the notification comes from the listbox
If (hwnd = hLB) {
;Get item count. 395 = LB_GETCOUNT
SendMessage 395, 0, 0,, ahk_id %hwnd%
iCount := ErrorLevel
;Check for error
If (ErrorLevel = 0xFFFFFFFF)
Return
;Get the bottom edge of the last item. 408 = LB_GETITEMRECT
VarSetCapacity(uRect, 16, 0)
SendMessage 408, iCount - 1, &uRect,, ahk_id %hLB% ;%
iBottomEdge := (ErrorLevel <> 0xFFFFFFFF) ? NumGet(uRect, 12) : 0
;Extract the Y coordinate of the mouse click from lParam (high word)
iY := lParam >> 16
;Check if mouse click is under or over bottom edge
If (iY > iBottomEdge)
GoSub ListBoxDoubleClickOffItem ;The dblclick was off an item
Else
GoSub ListBoxDoubleClickOnItem ;The dblclick was on an item
}
}
ListBoxDoubleClickOnItem:
MsgBox You double-clicked on an item!
Return
ListBoxDoubleClickOffItem:
MsgBox You double-clicked off an item!
Return |
Enjoy!
Last edited by TheGood on Tue Feb 23, 2010 4:43 am; edited 2 times in total |
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 828
|
Posted: Sun Dec 28, 2008 8:30 pm Post subject: |
|
|
Im planning on learning to GUIs (Ive been avoiding this for a while due to laziness). This will be useful for that. _________________ Click here to join #AHK channel in IRC for general chat and quick help. |
|
| Back to top |
|
 |
Donny Bahama
Joined: 30 Dec 2006 Posts: 132 Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
|
Posted: Mon Mar 30, 2009 8:49 pm Post subject: Me, too |
|
|
| I'd like to know, too. Is this possible? |
|
| Back to top |
|
 |
Donny Bahama
Joined: 30 Dec 2006 Posts: 132 Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
|
Posted: Mon Mar 30, 2009 8:56 pm Post subject: |
|
|
Found this buried in the help file:
| Code: | if A_GuiEvent <> DoubleClick
return
; else fall through to the next label:
5ButtonOK:
GuiControlGet, MyListBox
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|