Jump to content

How to identify a double click on a GUI label


Recommended Posts

Well that is what I need... Identify a double click on a GUI label

Something like this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$n1 = "Null"
$n2 = "Null"
GUICreate("Teste",200,200)
$Name1 = GUICtrlCreateLabel($n1,0,0,100,100,$SS_CENTER)
$Name2 = GUICtrlCreateLabel($n2,0,100,100,100,$SS_CENTER)
GUISetState(@SW_SHOW)

While 1
; If the label Name1 is double clicked then it pops up a inputbox
If DoubleClick($Name1) Then
$n1 = InputBox("Name","Name")
GUICtrlSetData($Name1,$n1)
EndIf
WEnd
Link to comment
Share on other sites

Hi,

On a label it won't be very accurate as you can see with this example :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Local $n1 = "Null", $n2 = "Null"

GUICreate("Teste", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Name1 = GUICtrlCreateLabel($n1, 0, 0, 100, 100, $SS_CENTER)
GUICtrlSetOnEvent($Name1, "_Name1")

$Name2 = GUICtrlCreateLabel($n2, 0, 100, 100, 100, $SS_CENTER)
GUICtrlSetOnEvent($Name2, "_Name1")

GUISetState()

While 1
   Sleep(1000)
WEnd

Func _Name1()
   Local Static $hTimerDbClick = 0
   If $hTimerDbClick = 0 Or TimerDiff($hTimerDbClick) > 500 Then
      $hTimerDbClick = TimerInit()
      Return ;
   EndIf

   $n1 = InputBox("Name", "Name")
   GUICtrlSetData($Name1, $n1)
EndFunc

Func _Exit()
    Exit
EndFunc

You should use another control that handles more than 1 click per second.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

I'm not a good coder, but try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

Global $Flag

$hGui = GUICreate("", 150, 100)
$hLabel = GUICtrlCreateLabel("DOUBLE_CLICK", 20, 20, 100, 20)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "TEST_WM_COMMAND")

While 1
 $msg = GUIGetMsg()
 Switch $msg
  Case $GUI_EVENT_CLOSE
   ExitLoop
 EndSwitch
 If $Flag = True Then
  MsgBox(0, 0, "Double click")
  $Flag = False
 EndIf
WEnd

Func TEST_WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
 Local Const $STN_DBLCLK = 1
 Local $nID = BitAND($wParam, 0xFFFF)
 Local $nCode = BitShift($wParam, 16)
 If $nID = $hLabel And $nCode = $STN_DBLCLK Then $Flag = True
 Return $GUI_RUNDEFMSG
EndFunc   ;==>TEST_WM_COMMAND
Edited by johnmcloud
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...