Sign in to follow this  
Followers 0
MrChris

GUI button not working!

7 posts in this topic

What am I missing in order to make this sample GUI button work. Right now it does noting. It shoudl open up notepad.

#include <GuiConstants.au3>

GuiCreate("Sample GUI", 296, 120,-1, -1 )

$Group_1 = GuiCtrlCreateGroup("Sample GUI", 10, 10, 280, 100)

$Button_2 = GuiCtrlCreateButton("Open Notepad", 20, 30, 80, 40)
GUICtrlSetOnEvent(-1, "notepad")

Func notepad()
        RunWait(@SystemDir & '\notepad.exe')
EndFunc

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;
    EndSelect
WEnd
Exit

Thanks,

MrChris

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Run("Notepad.exe")

If you can type it in the start>run then you can use Run().

Edited by gamepin126

Share this post


Link to post
Share on other sites

I have RunWait(@SystemDir & '\notepad.exe') in there. I changed it with your code and nothing still.

Share this post


Link to post
Share on other sites

You need to make a new case for that button.

#include <GuiConstants.au3>

GuiCreate("Sample GUI", 296, 120,-1, -1 )

$Group_1 = GuiCtrlCreateGroup("Sample GUI", 10, 10, 280, 100)

$Button_2 = GuiCtrlCreateButton("Open Notepad", 20, 30, 80, 40)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $Button_2
            Run("Notepad.exe")
            
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

gamepin came with the other solution "not to use events" so a more elaborate OnEvent sample would be:

#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
GuiCreate("Sample GUI", 296, 120,-1, -1 )

$Group_1 = GuiCtrlCreateGroup("Sample GUI", 10, 10, 280, 100)

$Button_2 = GuiCtrlCreateButton("Open Notepad", 20, 30, 80, 40)
GUICtrlSetOnEvent(-1, "notepad")

Func notepad()
        RunWait(@SystemDir & '\notepad.exe')
EndFunc

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
    sleep(1000) ;Relax the process, save cpu
WEnd
Exit

I have not tested this code so I could have typos :D

EDIT: Damn typos!

Edited by Uten

Share this post


Link to post
Share on other sites

@ Uten

Ahh yes that was it. Thanks a ton.

MrChris

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