Jump to content

GUICtrlSetOnEvent with MouseDown


Recommended Posts

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

  • Moderators

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):

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

  • Moderators

Manfred,

And thank you for the $WS_EX_DLGMODALFRAME tip. I do enjoy this forum. >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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...