Jump to content

Monitor GUICtrlCreateButton click


Ktulu789
 Share

Recommended Posts

Hi people! How are you doing?

I have a GUI I created that has some buttons. I monitor them with While...GUIGetMsg...Switch...Case

Is that the only way to monitor clicks or buttons pressed?

 

The GUI simply has some Labels, one has a counter. One button counts one more and updates the label, the other resets the counter to zero and shows a message first. The problem is that the message appears for a split second and then the counter at 1 is shown. I want it to stop until the next click on the button.

I tried to nest While...GUIGetMsg...Switch...Case inside the other While...GUIGetMsg.... and it simply stops responding, no click works.

Maybe I'm wrong But I think I remember there was another way to monitor buttons clicks.

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

You could use Adlibregister to monitor if the button was clicked or not, for example:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
Global $g_bStart = False, $g_iCount = 0

GUICreate("Counter Example", 200, 65)
Global $g_idCounter = GUICtrlCreateLabel("", 5, 5, 190, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER))

Global $g_idStart = GUICtrlCreateButton("Start", 5, 30, 95, 30)
Global $g_idReset = GUICtrlCreateButton("Reset", 100, 30, 95, 30)
GUISetState()
AdlibRegister("_Counter", 1000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $g_idStart
            $g_bStart = $g_bStart = False ? True : False
            GUICtrlSetData($g_idStart, $g_bStart = False ? "Start" : "Stop")
        Case $g_idReset
            $g_bStart = False
            GUICtrlSetData($g_idCounter, "")
    EndSwitch
WEnd

Func _Counter()
    Switch $g_bStart
        Case True
            GUICtrlSetData($g_idCounter, $g_iCount)
            $g_iCount += 1
        Case False
            ;~ Do nothing
    EndSwitch
EndFunc

 

Link to comment
Share on other sites

  • Moderators

Ktulu789,

You should be able to do what you want within a GUIGetMsg loop. Please post the code you have tried (see here how to do it) and then we can see what exactly why you are having problems.

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

  • 2 weeks later...

Hi guys!
Thanks for your replies! I was using a GUIGetMsg loop and changed for GUICtrlSetOnEvent from GUIOnEventMode. Anyway the error was some loops that recalled themselves, hence skipping steps.
The original code was using MsgBox to show the messages and I changed them to a GUI to avoid reflashing the window on screen.

It was something like

"message"
Enter
Message with counter 45 times
Enter everytime
Closing message.
Enter
(There were 30something messages, they repeated 45 times each to allow me to count).

Sometimes I needed to restart a loop of 45 or jump to the next/previous message and I had hotkeys for that which worked after dismissing the current MsgBox. When I changed the MsgBoxes for the GUI and started replacing the next/previous MsgBoxes it just went to the next thing in line. Bad code.

Anyway I wanted to find the GUIOnEventMode method and couldn't find it on the help file easily (as in GUICreate related. Normally you create a GUI and then want to add functional buttons and stuff, but in the Related section only appears GUIGetMsg).

I fixed the parts that recalled the message functions from the previous/next functions and averything is fine. Also the While 1 GUIGetMsg polling is gone thanks to you!

Sorry for the late response, work and study make things harder :P

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

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