Jump to content
Sign in to follow this  
BrettF

DBL and SNG Clicks on controls

Recommended Posts

BrettF

Well here is my code:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

;Global $playing_state = -1
Global $DoubleClicked = 0, $clicked = 0, $current_viz = 1

$viz_width = 800;@DesktopWidth
$viz_height = 600;@DesktopHeight
$on_top = 0

$win = GUICreate("Visualization Test", $viz_width, $viz_height, Default, Default, $WS_POPUP, $on_top)

$lbl = GUICtrlCreateLabel("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)
$viz = GUICtrlCreatePic("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case - 3
            Exit
    EndSwitch
    Switch $DoubleClicked
        Case $lbl
            MsgBox(0, "", "DBLCLK")
            $DoubleClicked = 0
    EndSwitch
    Switch $clicked
        Case $lbl
            If Not $DoubleClicked Then MsgBox(0, "", "CLK")
            $clicked = 0
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local Const $STN_DBLCLK = 1, $STN_CLICKED = 0
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode
        Case $STN_CLICKED
            $clicked = $nID
        Case $STN_DBLCLK
            $DoubleClicked = $nID
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Whenever I try to do a double click, the single click message comes up and then double click. How can I fix this?

Is there also a way to make it register dragging of the window (as not not call the click function), and display a message on right click?

Thanks,

Brett

Share this post


Link to post
Share on other sites
Melba23

BrettF,

I am assuming you want both single and double clicks to register:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

;Global $playing_state = -1
Global $DoubleClicked = 0, $clicked = 0, $current_viz = 1

$viz_width = 800;@DesktopWidth
$viz_height = 600;@DesktopHeight
$on_top = 0

$win = GUICreate("Visualization Test", $viz_width, $viz_height, Default, Default, $WS_POPUP, $on_top)

$lbl = GUICtrlCreateLabel("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)
$viz = GUICtrlCreatePic("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case - 3
            Exit
    EndSwitch

    Switch $clicked
        Case $lbl
            $Begin = TimerInit()
            Do
                Switch $DoubleClicked
                    Case $lbl
                        MsgBox(0, "", "DBLCLK")
                        $DoubleClicked = 0
                        $Clicked = 0
                EndSwitch
            Until TimerDiff($Begin) > 100 ; Adjust to suit required double clicking speed
            If $Clicked Then MsgBox(0, "", "CLK")
            $clicked = 0
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local Const $STN_DBLCLK = 1, $STN_CLICKED = 0
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode
        Case $STN_CLICKED
            $clicked = $nID
        Case $STN_DBLCLK
            $DoubleClicked = $nID
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
BrettF

Why thank you. Exactly what I was after. Tweaked it to get double click speed from RegRead ("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"). Still wondering about right click though :D

Share this post


Link to post
Share on other sites
Authenticity

You can use GetDoubleClickTime() to get that instead.

Share this post


Link to post
Share on other sites
martin

Why thank you. Exactly what I was after. Tweaked it to get double click speed from RegRead ("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"). Still wondering about right click though :D

I think Melba23's code could go wrong once every 6 thousnad years say, because you could click just at the end of the time period for detecting the double click. So I think it is better to time f

rom the click, which happens first, rather than the double click. Also, you can get round the clkick on drag using another flag.

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

;Global $playing_state = -1
Global $DoubleClicked = 0, $clicked = 0, $current_viz = 1

$viz_width = 800;@DesktopWidth
$viz_height = 600;@DesktopHeight
$on_top = 0

$win = GUICreate("Visualization Test", $viz_width, $viz_height, Default, Default, $WS_POPUP, $on_top)

$lbl = GUICtrlCreateLabel("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)
$viz = GUICtrlCreatePic("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)

GUISetState()
Global $esmNO = 0
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg(0x0232, "ESM");$WM_EXITSIZEMOVE
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case - 3
            Exit
    EndSwitch

    Switch $clicked
        Case $lbl
            If $clicked Then
                $Begin = TimerInit()


                Do
                    Sleep(10)
                Until TimerDiff($Begin) > 100; Adjust to suit required double clicking speed
                If $DoubleClicked Then
                    Switch $DoubleClicked
                        Case $lbl
                            MsgBox(0, "", "DBLCLK")
                            $DoubleClicked = 0
                            $clicked = 0
                    EndSwitch
                Else
                    If Not $esmNO Then
                        MsgBox(0, "", "CLK")
                    Else
                        $esmNO = 0
                    EndIf

                    $clicked = 0
                EndIf
            EndIf
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local Const $STN_DBLCLK = 1, $STN_CLICKED = 0
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode
        Case $STN_CLICKED
            $clicked = $nID
        Case $STN_DBLCLK
            $DoubleClicked = $nID
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Func esm()
    $esmNO = 1
    ConsoleWrite("esmed" & @CRLF)
EndFunc  ;==>esm

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Melba23

martin,

Now there is the difference between a hobbyist like me and a professional! :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
BrettF
ProgAndy

I would do it this way:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Global Const $iDoubleClickTime = _GetDoubleClickTime()
Func _GetDoubleClickTime()
    Local $aResult = DllCall("user32.dll", "uint", "GetDoubleClickTime")
    If @error Then Return SetError(1,0,100)
    Return $aResult[0]
EndFunc

;Global $playing_state = -1
Global $DoubleClicked = 0, $clicked = 0, $current_viz = 1

$viz_width = 800;@DesktopWidth
$viz_height = 600;@DesktopHeight
$on_top = 0

$win = GUICreate("Visualization Test", $viz_width, $viz_height, Default, Default, $WS_POPUP, $on_top)
GUISetBkColor(0x123456)
$lbl = GUICtrlCreateLabel("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)
$viz = GUICtrlCreatePic("", 0, 0, $viz_width, $viz_height, 0x0100, 0x00100000)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case - 3
            Exit
    EndSwitch
    If $clicked Then
        $tDblClickTime = TimerInit()
        Do
            Switch $DoubleClicked
                Case 0
                    Sleep(10)
                Case $lbl
                    MsgBox(0, "", "DBLCLK")
                    ExitLoop
            EndSwitch
            If $DoubleClicked Then $clicked = 0
        Until TimerDiff($tDblClickTime) > $iDoubleClickTime
        $DoubleClicked = 0
        Switch $clicked
            Case 0
                ; nothing
            Case $lbl
                If Not $DoubleClicked Then MsgBox(0, "", "CLK")
        EndSwitch
        $clicked = 0
    EndIf
WEnd

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local Const $STN_DBLCLK = 1, $STN_CLICKED = 0
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode
        Case $STN_CLICKED
            $clicked = $nID
        Case $STN_DBLCLK
            $DoubleClicked = $nID
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
kjcdude

Thanks to whoever created this.

Very useful code to see when a guictrl is clicked on.

Share this post


Link to post
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
Sign in to follow this  

×