Jump to content
TheWizEd

Get Event

Recommended Posts

TheWizEd

I want to capture the button click but I only get the canvas click.  How do I get the button click?

Global $hCanvas= GUICreate("Canvas", 500, 500)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"CanvasClicked")

GUISetState(@SW_SHOW)

Local $idButton = GUICtrlCreateButton("hello",0,0,100,25)
GUICtrlSetOnEvent(-1, "ButtonClicked")
 

Share this post


Link to post
Share on other sites
Melba23

TheWizEd,

I imagine it is because the GUISetOnEvent handler takes precedence over the GUICtrlSetOnEvent one and so swallows the click before the button gets a chance to see it. You could always do something like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt("GUIOnEventMode", 1)

Global $hCanvas= GUICreate("Canvas", 500, 500)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"CanvasClicked")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Local $idButton = GUICtrlCreateButton("hello",0,0,100,25)

 GUISetState(@SW_SHOW)

 While 1
     Sleep(10)
 WEnd

Func CanvasClicked()
    If (GUIGetCursorInfo($hCanvas))[4] = $idButton Then
        MsgBox($MB_SYSTEMMODAL, "Clicked", "Button")
    Else
        MsgBox($MB_SYSTEMMODAL, "Clicked", "Canvas")
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

But why do you need to detect a mouse event on the entire GUI in the first place?

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
TheWizEd
Posted (edited)

I'm trying to see if the user can move the control.  But also want to know if the user just clicks the canvas.

Edited by TheWizEd

Share this post


Link to post
Share on other sites
Melba23

TheWizEd,

So how will you differentiate between a click and a move?

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
TheWizEd
1 hour ago, Melba23 said:

TheWizEd,

So how will you differentiate between a click and a move?

M23

Haven't figured that out yet. I'm trying message loop instead.

Share this post


Link to post
Share on other sites
Melba23

TheWizEd,

How about a draggable border:

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

Global Const $SC_DRAGMOVE = 0xF012

$hGUI = GUICreate("Test", 300, 200)

Global $cLabel = GUICtrlCreateLabel("", 95, 45, 90, 40)
GUICtrlSetBkColor($cLabel, 0x00FF00)
GUICtrlSetState($cLabel, $GUI_DISABLE) ; Needs to be disabled for the button to work

$cButton = GUICtrlCreateButton("Press Me!", 100, 50, 80, 30)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _ControlMove()
        Case $GUI_EVENT_PRIMARYUP
            _ControlStop()
        Case $cButton
            ConsoleWrite("Button Pressed" & @CRLF) ; Just to show it works!
    EndSwitch
WEnd

Func _ControlMove()
    ; Check if over label
    Local $aCurPos = GUIGetCursorInfo()
    If @error Then Return False
    If $aCurPos[4] = $cLabel Then
        ; Enable label to enable drag
        GUICtrlSetState($cLabel, $GUI_ENABLE)
        ; Delete button
        GUICtrlDelete($cButton)
        ; Allow label drag
        _SendMessage(GUICtrlGetHandle($cLabel), $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndIf

EndFunc   ;==>_ControlMove

Func _ControlStop()
    ; Check if over label
    Local $aCurPos = GUIGetCursorInfo()
    If @error Then Return False
    If $aCurPos[4] = $cLabel Then
        ; Disable label again
        GUICtrlSetState($cLabel, $GUI_DISABLE)
        ; Recreate button in new position
        $aPos = ControlGetPos($hGUI, "", $cLabel)
        $cButton = GUICtrlCreateButton("Press Me!", $aPos[0] + 5, $aPos[1] + 5, 80, 30)
    EndIf

EndFunc   ;==>_ControlStop

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

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

×