closeupman Posted January 10, 2005 Posted January 10, 2005 I'm rewriting my code from start, but now for some reason the GuiSetOnEvent is not working. expandcollapse popup#include <guiconstants.au3> #include <string.au3> #include <Array.au3> ;setup and initialization Const $ENABLE=1 Const $DISABLE=0 ;set Event Mode so can do REGULAR Windows type Events Opt("GuiOnEventMode", $ENABLE) ;used for main screen, made global so can create child to it Global $mainWindowID GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents") $mainWindowId=CreateMainWindow() msgbox(0,"",$mainWindowId) ShowWindow($mainWindowId) While 1 sleep(10) WEnd Func CreateMainWindow() ;create the Main Window ;set the Functions that will be called if a button is clicked ;(i.e. event is a mouse click, so on an event we go to the corresponding function) ;return the Window id, cuz we need this to manipulate it later ;the button ids can be local because we set the EVENTs for them here ;so we don't need them anymore...I THINK!! local $mainWinID,$goToLettersID,$goToNumbersID,$goToSongsID,$goToQuitID $mainWinID=GUICreate("Fun Time Learining",600,400,0,0) $goToLettersID=GUICtrlCreateButton("Alphabet",100,100,50,30) $goToNumbersID=GUICtrlCreateButton("Numbers",100,175,50,30) $goToSongsID=GUICtrlCreateButton("Songs",100,240,50,30) $goToQuitID=GUICtrlCreateButton("Quit",350,340,50,30) GUICtrlSetOnEvent($goToLettersID,"AlphabetChosen") GUICtrlSetOnEvent($goToNumbersID,"NumbersChosen") GUICtrlSetOnEvent($goToSongsID,"SongsChosen") GUICtrlSetOnEvent($goToQuitID,"QuitChosen") return $mainWinID endFunc Func ShowWindow($id) ;show the window, maximized, specified by $id) GUISetState(@SW_MAXIMIZE,$id) endFunc Func AlphabetChosen() msgbox(0,"","Alpha",2) EndFunc Func NumbersChosen() msgbox(0,"","Num",2) EndFunc Func SongsChosen() msgbox(0,"","Songs",2) EndFunc Func QuitChosen() msgbox(0,"","Quit",2) Exit EndFunc Func SystemEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Exit Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Case @GUI_CTRLID = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc
SvenP Posted January 10, 2005 Posted January 10, 2005 You placed the GuiSetOnEvent functions BEFORE you created any GUI window. So the function does never know from which window to fetch the events. If you want SystemEvents() to fetch events from the $mainWindowID, you could change the code to: .... $mainWindowId=CreateMainWindow() GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents",$mainWindowId) GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents",$mainWindowId) GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents",$mainWindowId) .... Regards, -Sven
jpm Posted January 10, 2005 Posted January 10, 2005 usely a GUI start this way$mainWindowId=CreateMainWindow() GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents") msgbox(0,"",$mainWindowId) GUISetState() After I think every thing is working
closeupman Posted January 10, 2005 Author Posted January 10, 2005 (edited) You placed the GuiSetOnEvent functions BEFORE you created any GUI window. So the function does never know from which window to fetch the events.If you want SystemEvents() to fetch events from the $mainWindowID, you could change the code to:....$mainWindowId=CreateMainWindow()GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents",$mainWindowId)GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents",$mainWindowId)GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents",$mainWindowId)....Regards,-Sven<{POST_SNAPBACK}>Ok...thxs...it worked by placing it after....didn't think about that cuz was thinking it as a system,independent messages.So that means if I create another Window later in my code I have to repeat these?thxs Sven & JpmNow, I tried to close just the 2nd window...but for some reason it closes bothexpandcollapse popup#include <guiconstants.au3> #include <string.au3> #include <Array.au3> ;setup and initialization Const $ENABLE=1 Const $DISABLE=0 ;set Event Mode so can do REGULAR Windows type Events Opt("GuiOnEventMode", $ENABLE) ;used for main screen, made global so can create child to it Global $mainWindowID $mainWindowId=CreateMainWindow() GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents") ShowWindow($mainWindowId) While 1 sleep(10) WEnd Func CreateMainWindow() ;create the Main Window ;this is the 1st screen the user sees ;from here the user can go to ;letters (learn the alphabet), numbers (learn numbers), or songs (learn songs) ;set the Functions that will be called if a button is clicked ;(i.e. event is a mouse click, so on an event we go to the corresponding function) ;return the Window id, cuz we need this to manipulate it later ;the button ids can be local because we set the EVENTs for them here ;so we don't need them anymore...I THINK!! local $mainWinID,$goToLettersID,$goToNumbersID,$goToSongsID,$goToQuitID $mainWinID=GUICreate("Fun Time Learining",600,400,0,0) $goToLettersID=GUICtrlCreateButton("Alphabet",100,100,50,30) $goToNumbersID=GUICtrlCreateButton("Numbers",100,175,50,30) $goToSongsID=GUICtrlCreateButton("Songs",100,240,50,30) $goToQuitID=GUICtrlCreateButton("Quit",350,340,50,30) GUICtrlSetOnEvent($goToLettersID,"AlphabetChosen") GUICtrlSetOnEvent($goToNumbersID,"NumbersChosen") GUICtrlSetOnEvent($goToSongsID,"SongsChosen") GUICtrlSetOnEvent($goToQuitID,"QuitChosen") return $mainWinID endFunc Func ShowWindow($id) ;show the window, maximized, specified by $id) GUISetState(@SW_MAXIMIZE,$id) endFunc Func AlphabetChosen() ;Alphabet button was chosen, so do the following: ; 1. set up & show the alphabet screen (i.e. the letters A-Z as buttons with a BACK button) ; 2. Set the event for the buttons ; 3. Can return to main loop cuz doing real Windows Events?! ;CreateAlphabetWindow() $alphaID=GUICreate("Alphabet",300,300,0,0) GuiSetOnEvent($GUI_EVENT_CLOSE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_MINIMIZE, "SystemEvents") GuiSetOnEvent($GUI_EVENT_RESTORE, "SystemEvents") ShowWindow($alphaID) msgbox(0,"","Alpha",2) EndFunc Func NumbersChosen() msgbox(0,"","Num",2) EndFunc Func SongsChosen() msgbox(0,"","Songs",2) EndFunc Func QuitChosen() msgbox(0,"","Quit",2) Exit EndFunc Func SystemEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) ;Only Exit program if the Main Window ;other just close the window and activate the Main Window If @Gui_WinHandle=$mainWindowID then Exit Else msgbox(0,"","HERE") WinClose(WinGetTitle("") ) WinActivate($mainWindowID) EndIf Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Case @GUI_CTRLID = $GUI_EVENT_RESTORE ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc Edited January 10, 2005 by closeupman
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