Jump to content
Sign in to follow this  
KickStarter15

[Solved] Question: Why $Button is working when Opt() function is used

Recommended Posts

KickStarter15
Posted (edited)

Hi Experts,

I wold like to ask this question since I don't have any idea as of this moment.

Question: Why "GUICtrlCreateButton()" will not work when Opt("GUIOnEventMode", 1) was set on a code.

I have my sample code from Help file. When you click on Button "$idNotepad" it won't run. But when you remove the Opt("GUIOnEventMode", 1) from your code the script will run after clicking the button.:blink:

#include <GUIConstantsEx.au3>
HotKeySet("{ESC}", "Terminate")
Opt("GUIOnEventMode", 1) ; this is my issue when declared, button won't work.

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    ; Create a button control.
    Local $idNotepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0
   ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop
            Case $idNotepad
                ; Run Notepad with the window maximized.
                $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
        EndSwitch
    WEnd

   GUIDelete($hGUI)
   If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

Func Terminate()
   Exit
EndFunc
Func _Close()
   Exit
EndFunc

 

Any advise from you Experts is very appreciated.

 

Thanks!

KS15

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
AutoBert
Posted (edited)

It couldn't work: The GuiOnEventMode ignores GuiGetMsg and needs GUICtrlSetOnEvent. You can read about this:

GUI Reference

it's very important to understand the concepts and the diferences between both.

Edited by AutoBert

Share this post


Link to post
Share on other sites
KickStarter15

@AutoBert,

Thanks, well that explained everything. Still need to read those guides further. However, when I don't want to use the Opt() OnEventMode, then clicked the "X" button from the GUI my loop will continue looping and GUI will pop-out many times but when I pressed close button which is "GUICtrlCreateButton()" no looping will happened and will close the GUI.

Maybe I just need to check my codes very well on how to handle this situation.^_^ I think I need to use the code without the Opt() event, I'll just find another way around if possible.


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
KickStarter15

Thanks for the guide @AutoBert, found the way to solve my question.:)


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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  

×