Jump to content

Events ButtonPress and ButtonRelease


Recommended Posts

#include <Constants.au3>
#include <WinAPI.au3>

Global Const $WM_MOUSEMOVE = 0x0200
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_LBUTTONUP = 0x0202

Global $hGUI
Global $Button, $hButton
Global $hFunc, $pFunc
Global $hOldProc
Global $fPressed = False

$hFunc = DllCallbackRegister('ButtonProc', 'int', 'hwnd;uint;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)

$hGUI = GUICreate('Test', 100, 100)
$Button = GUICtrlCreateButton('Text', 20, 40, 60, 23)
$hButton = GUICtrlGetHandle(-1)

$hOldProc = _WinAPI_GetWindowLong($hButton, $GWL_WNDPROC)
_WinAPI_SetWindowLong($hButton, $GWL_WNDPROC, $pFunc)

GUISetState()

Do
Until GUIGetMsg() = -3

GUIDelete()
DllCallbackFree($hFunc)
Exit


Func ButtonProc($hwnd, $iMsg, $iwParam, $ilParam)
    Switch $iMsg
        Case $WM_LBUTTONDOWN
            ConsoleWrite('Pressed' & @LF)
            $fPressed = True
        Case $WM_LBUTTONUP
            ConsoleWrite('Release' & @LF)
            $fPressed = False
        Case $WM_MOUSEMOVE
            If $fPressed Then ConsoleWrite('Still pressed' & @LF)
    EndSwitch
    
    Return _WinAPI_CallWindowProc($hOldProc, $hwnd, $iMsg, $iwParam, $ilParam)
EndFunc

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...