AutoHotkey Community

It is currently May 26th, 2012, 12:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: December 28th, 2008, 7:59 pm 
Offline

Joined: July 30th, 2007, 11:32 pm
Posts: 581
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 February 23rd, 2010, 4:43 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2008, 8:30 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Im planning on learning to GUIs (Ive been avoiding this for a while due to laziness). This will be useful for that.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Me, too
PostPosted: March 30th, 2009, 8:49 pm 
Offline

Joined: December 30th, 2006, 4:13 pm
Posts: 132
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
I'd like to know, too. Is this possible?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2009, 8:56 pm 
Offline

Joined: December 30th, 2006, 4:13 pm
Posts: 132
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Found this buried in the help file:
Code:
if A_GuiEvent <> DoubleClick
    return
; else fall through to the next label:
5ButtonOK:
GuiControlGet, MyListBox


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group