KickStarter15 Posted June 16, 2018 Share Posted June 16, 2018 (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. expandcollapse popup#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 June 16, 2018 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. Link to comment Share on other sites More sharing options...
AutoBert Posted June 16, 2018 Share Posted June 16, 2018 (edited) It couldn't work: The GuiOnEventMode ignores GuiGetMsg and needs GUICtrlSetOnEvent. You can read about this: GUI Reference GUI Concepts GUI MessageLoop Mode GUI OnEvent Mode it's very important to understand the concepts and the diferences between both. Edited June 16, 2018 by AutoBert Link to comment Share on other sites More sharing options...
KickStarter15 Posted June 16, 2018 Author Share Posted June 16, 2018 @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. Link to comment Share on other sites More sharing options...
KickStarter15 Posted June 16, 2018 Author Share Posted June 16, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now