Sign in to follow this  
Followers 0
houseonfire

Button Command

10 posts in this topic

Can someone please tell me how give a button in a GUI a command?

I'm really new to using the GUI..

Share this post


Link to post
Share on other sites



$button_1 = guictrlcreatebutton("Go", left, top, width, height)

if you want that button to do something, then example:

While 1
$msg = GuiGetMsg()
if $msg = (button name) then
(do something here)
endif

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I was gonna try that.. but the $msg thing made me think its gonna pop up a message.

Thank you very much.

$Button1 = GUICtrlCreateButton("test", 32, 112, 89, 41, 0)
While 1
    $msg = GuiGetMsg()
    If $msg = $Button1 Then
        MSGBox (0, "test", "test")
    endif
WEnd

Doesn't seem to work :s

Edited by houseonfire

Share this post


Link to post
Share on other sites

Thats just the thing.. I've been searching for this for an hour and cant find it.

Share this post


Link to post
Share on other sites

I tried that code to give a button some commands and it works great, but, whenever I click any button, I cannot close the Form via the X on the window corner, its like frozen waiting for the "While" to end.

Is there a way to prevent this?

thanks in advance.

Share this post


Link to post
Share on other sites

I tried that code to give a button some commands and it works great, but, whenever I click any button, I cannot close the Form via the X on the window corner, its like frozen waiting for the "While" to end.

Is there a way to prevent this?

thanks in advance.

Try to add this in your While loop!

;Check if user clicked on the close button
If $msg = $GUI_EVENT_CLOSE
   ;Destroy the GUI including the controls
    GUIDelete()
   ;Exit the script
    Exit
EndIf

Share this post


Link to post
Share on other sites

You actually need to create a GUI for it:

CODE

#include <GUIConstants.au3>

$GUI1 = GUICreate("GUI!", 346, 179, 193, 115)

$Button1 = GUICtrlCreateButton("Press Me!!!", 8, 8, 331, 161, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

msgbox(0, "Test", "Testing!!!")

EndSwitch

WEnd

Share this post


Link to post
Share on other sites

Thank you!

That worked great for me.

Still need to understand in detail all the code, because I just did a copy paste. Never worked with GUI before in autoit.

Thanks again.

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
Sign in to follow this  
Followers 0