Sign in to follow this  
Followers 0
sensalim

Double click or right click on a guictrlcreatebutton

2 posts in this topic

Looked at help, it says

Enables a button to send BN_KILLFOCUS and BN_SETFOCUS notification messages to its parent window. Note that buttons send the BN_CLICKED notification message regardless of whether it has this style. To get BN_DBLCLK notification messages, the button must have the BS_RADIOBUTTON or BS_OWNERDRAW style.

Then I looked at GUIRegisterMsg() and I got lost.

Anyone got a quick simple example? I prefer right click actually...

Thank you!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi! Try this:

#include <GuiConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>

Global Const $BN_CLICKED = 0
Global Const $BN_DBLCLK = 5

Global $DllHandle = DllOpen("user32.dll")

$hGui = GUICreate("Double Click Demo", 400, 300)

$button = GUICtrlCreateButton("start", 10, 10, 50, 25, $BS_NOTIFY)

$aBtnPos = ControlGetPos($hGui, "", $button)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState()

While GUIGetMsg() <> -3
    If _IsPressed("02", $DllHandle) Then
        $tPoint = _WinAPI_GetMousePos(True, $hGui)
        
        $X = DllStructGetData($tPoint, "X")
        $Y = DllStructGetData($tPoint, "Y")
        
        If ($X >= $aBtnPos[0]) And ($X <= $aBtnPos[0] + $aBtnPos[2]) _
            And ($Y >= $aBtnPos[1]) And ($Y <= $aBtnPos[1] + $aBtnPos[3]) Then _DebugPrint("Right mouse click", @ScriptLineNumber)
            Sleep(100)
    EndIf   
WEnd

DllClose($DllHandle)

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)       ;HiWord
    $nID            = BitAnd($wParam, 0x0000FFFF) ;LoWord
    
    If $nID = $button Then
        Switch $nNotifyCode
        Case $BN_CLICKED
            _DebugPrint("Left mouse click", @ScriptLineNumber)
        Case $BN_DBLCLK
            _DebugPrint("Left mouse double click", @ScriptLineNumber)
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite("+=====================================" & @LF & _
                "--> Script Line (" & $line & "):" & @LF & "!" & @TAB & $s_text & @LF & _
                "+=====================================" & @LF)
EndFunc
:D Edited by rasim

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  
Followers 0