Manfred Posted August 24, 2009 Share Posted August 24, 2009 I made a simple GUI: GUICtrlSetOnEvent($Button_Stop, "Button_Stop") It works, the Func Button_Stop is executed, but after relase the mousebutton, not in time when clicking left. Is there any way, to execute it at once with MouseDown? Regards Manfred Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2009 Moderators Share Posted August 24, 2009 Manfred, Buttons only activate on mouse button up. Try using a label if you need to get a response on mouse button down: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUICtrlCreateLabel("Test", 10, 10, 80, 30, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetOnEvent(-1, "Test") GUICtrlSetBkColor(-1, 0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func Test() ConsoleWrite("Hit" & @CRLF) EndFunc Func OnExit() Exit EndFunc Or you could use something like this which ignores the actual button and looks for a click on the rectangle of the button coordinates (credit to Malkey for the basic idea): expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUICtrlCreateButton("Test", 10, 10, 80, 30) ; Note no event attached GUISetState() ; When left mouse button pressed - check if within button rectangle GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "InRect") While 1 Sleep(10) WEnd Func OnExit() Exit EndFunc Func InRect() ; Set client mouse coord option and save current setting $iOldOpt = Opt("MouseCoordMode", 2) ; Set up rectangle at button coords Local $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($tRect, "Left", 10) DllStructSetData($tRect, "Top", 10) DllStructSetData($tRect, "Right", 90) DllStructSetData($tRect, "Bottom", 40) ; Get mouse position Local $aPos = MouseGetPos() ; See if mouse over rectangle Local $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $aPos[0], "int", $aPos[1]) If @error Then Return ; Act if over button If $aResult[0] <> 0 Then ConsoleWrite("Hit" & @CRLF) ; Reset original mouse coord option Opt("MouseCoordMode", $iOldOpt) EndFunc I hope one of these is useful. >_< 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 Link to comment Share on other sites More sharing options...
Manfred Posted August 25, 2009 Author Share Posted August 25, 2009 Buttons only activate on mouse button up. Try using a label if you need to get a response on mouse button down: GUICtrlCreateLabel("Test", 10, 10, 80, 30, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_DLGMODALFRAME) Or you could use something like this which ignores the actual button and looks for a click on the rectangle of the button coordinates (credit to Malkey for the basic idea): I hope one of these is useful. >_< Many thanks, also for your very fast response! Using labels instead of button is my way, by adding '$WS_EX_DLGMODALFRAME' it looks like a button. I did and it works as needed! Also I can play with colors for it - in the future. The use of the rectangle I think is not possible because of more than one button. Best regards and many thanks Manfred Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 25, 2009 Moderators Share Posted August 25, 2009 Manfred,And thank you for the $WS_EX_DLGMODALFRAME tip. I do enjoy this forum. >_< 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 Link to comment Share on other sites More sharing options...
Manfred Posted August 25, 2009 Author Share Posted August 25, 2009 And thank you for the $WS_EX_DLGMODALFRAME tip. I do enjoy this forum. Don't forget: #include <WindowsConstants.au3> for this >_< Link to comment Share on other sites More sharing options...
Info Posted August 25, 2009 Share Posted August 25, 2009 (edited) $question = "" ;your question here If StringInStr($question,"GUI") <> 0 Then MsgBox(0,'IT IS GUI RELATED!',"POST IT IN THE GUI SUPPORT FORUM! :)") Edited August 25, 2009 by Info Link to comment Share on other sites More sharing options...
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