TheWizEd Posted March 10, 2018 Posted March 10, 2018 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")
Moderators Melba23 Posted March 11, 2018 Moderators Posted March 11, 2018 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheWizEd Posted March 11, 2018 Author Posted March 11, 2018 (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 March 11, 2018 by TheWizEd
Moderators Melba23 Posted March 11, 2018 Moderators Posted March 11, 2018 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheWizEd Posted March 11, 2018 Author Posted March 11, 2018 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.
Moderators Melba23 Posted March 11, 2018 Moderators Posted March 11, 2018 TheWizEd, How about a draggable border: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now