Jump to content

GUI button not working!


Recommended Posts

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

Link to comment
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
Link to comment
Share on other sites

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