eyegeegeewhy Posted February 18, 2008 Share Posted February 18, 2008 Hi I am trying to create a GUI with multiple child windows. I have got the GUi working with the chilren. But am having trouble getting buttons on the child windows to do anything. Im not sure if I have gone about this the best way should i be using OnEvent? What i want is $button one to launch function test Code is below I have commented out the DB bits as they are not needed yet expandcollapse popup#include <GUIConstants.au3> #include <sqlite.au3> #include <sqlite.dll.au3> ; Start the Database ;_SQLite_Startup () ;_SQLite_Open (@ScriptDir&"\game_data.db") ;_SQLite_Open () #Region ### START Koda GUI section ### Form=c:\users\jordan\desktop\autoit\game_ap\main.kxf $MAIN_SCREEN = GUICreate("GAMME_APP", 481, 336, 477, 432) $Menu = GUICtrlCreateMenu("&Menu") $USER_MENU = GUICtrlCreateMenu("User", $Menu) $ADD_USER = GUICtrlCreateMenuItem("Add User", $USER_MENU) $DELETE_USER = GUICtrlCreateMenuItem("Delete User", $USER_MENU) $EDIT_USER = GUICtrlCreateMenuItem("Edit User", $USER_MENU) $SYSTEM_MENU = GUICtrlCreateMenu("System", $Menu) $ADD_SYSTEM = GUICtrlCreateMenuItem("Add System", $SYSTEM_MENU) $DELETE_SYSTEM = GUICtrlCreateMenuItem("Delete System", $SYSTEM_MENU) $EDIT_SYSTEM = GUICtrlCreateMenuItem("Edit System", $SYSTEM_MENU) $GAME_MENU = GUICtrlCreateMenu("Game", $Menu) $ADD_GAME = GUICtrlCreateMenuItem("Add Game", $GAME_MENU) $DELETE_GAME = GUICtrlCreateMenuItem("Delete Game", $GAME_MENU) $EDIT_GAME = GUICtrlCreateMenuItem("Edit Game", $GAME_MENU) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### Create all the child windows and hide them. $ADD_USER_SCREEN = GUICreate("Add User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) $Button1 = GUICtrlCreateButton("Button1", 168, 144, 75, 25, 0) GUISetState(@SW_HIDE) $DELETE_USER_SCREEN = GUICreate("Delete User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_USER_SCREEN = GUICreate("Edit User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $ADD_SYSTEM_SCREEN = GUICreate("Add System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $DELETE_SYSTEM_SCREEN = GUICreate("Delete System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_SYSTEM_SCREEN = GUICreate("Edit System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $ADD_GAME_SCREEN = GUICreate("Add Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $DELETE_GAME_SCREEN = GUICreate("Delete Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_GAME_SCREEN = GUICreate("Edit Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) #EndRegion ### While 1 $Msg = GUIGetMsg(1) $CTRLMsg = $Msg[0] $Win = $Msg[1] Select Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $MAIN_SCREEN GUIDelete() Exit ; Check to see if a child window has requested to be closed Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_USER_SCREEN WinSetState("Add User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_USER_SCREEN WinSetState("Edit User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_USER_SCREEN WinSetState("Delete User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_SYSTEM_SCREEN WinSetState("Add System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_SYSTEM_SCREEN WinSetState("Edit System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_SYSTEM_SCREEN WinSetState("Delete System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_GAME_SCREEN WinSetState("Add Game","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_GAME_SCREEN WinSetState("Edit Game","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_GAME_SCREEN WinSetState("Delete Game","",@SW_HIDE) ;Spawn the child windows when requested Case $CtrlMsg = $ADD_USER WinSetState("Add User","",@SW_SHOW) WinActivate("Add User") Case $CtrlMsg = $EDIT_USER WinSetState("Edit User","",@SW_SHOW) WinActivate("Edit User") Case $CtrlMsg = $DELETE_USER WinSetState("Delete User","",@SW_SHOW) WinActivate("Delete User") Case $CtrlMsg = $ADD_SYSTEM WinSetState("Add System","",@SW_SHOW) WinActivate("Add System") Case $CtrlMsg = $EDIT_SYSTEM WinSetState("Edit System","",@SW_SHOW) WinActivate("Edit System") Case $CtrlMsg = $DELETE_SYSTEM WinSetState("Delete System","",@SW_SHOW) WinActivate("Delete System") Case $CtrlMsg = $ADD_GAME WinSetState("Add Game","",@SW_SHOW) WinActivate("Add Game") Case $CtrlMsg = $EDIT_GAME WinSetState("Edit Game","",@SW_SHOW) WinActivate("Edit Game") Case $CtrlMsg = $DELETE_GAME WinSetState("Delete Game","",@SW_SHOW) WinActivate("Delete Game") Case $CtrlMsg = $Button1 AND $Win = $ADD_USER_SCREEN TEST() EndSelect WEnd Exit Func TEST() MsgBox(0,"title","test") EndFunc Link to comment Share on other sites More sharing options...
Swift Posted February 18, 2008 Share Posted February 18, 2008 (edited) Why Dont You Use While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 Test() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd It easier to read code when its not like mine...Run Tidy.exe and tidy your code but...Dont Use OnEvent...Its more complicated Edited February 18, 2008 by Swift Link to comment Share on other sites More sharing options...
eyegeegeewhy Posted February 18, 2008 Author Share Posted February 18, 2008 Hi I have tried making the changes where I think you mean but now the gui just closes #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstants.au3> #include <sqlite.au3> #include <sqlite.dll.au3> ; Start the Database _SQLite_Startup () _SQLite_Open (@ScriptDir&"\game_data.db") ;_SQLite_Open () #Region ### START Koda GUI section ### Form=c:\users\jordan\desktop\autoit\game_ap\main.kxf $MAIN_SCREEN = GUICreate("GAMME_APP", 481, 336, 477, 432) $Menu = GUICtrlCreateMenu("&Menu") $USER_MENU = GUICtrlCreateMenu("User", $Menu) $ADD_USER = GUICtrlCreateMenuItem("Add User", $USER_MENU) $DELETE_USER = GUICtrlCreateMenuItem("Delete User", $USER_MENU) $EDIT_USER = GUICtrlCreateMenuItem("Edit User", $USER_MENU) $SYSTEM_MENU = GUICtrlCreateMenu("System", $Menu) $ADD_SYSTEM = GUICtrlCreateMenuItem("Add System", $SYSTEM_MENU) $DELETE_SYSTEM = GUICtrlCreateMenuItem("Delete System", $SYSTEM_MENU) $EDIT_SYSTEM = GUICtrlCreateMenuItem("Edit System", $SYSTEM_MENU) $GAME_MENU = GUICtrlCreateMenu("Game", $Menu) $ADD_GAME = GUICtrlCreateMenuItem("Add Game", $GAME_MENU) $DELETE_GAME = GUICtrlCreateMenuItem("Delete Game", $GAME_MENU) $EDIT_GAME = GUICtrlCreateMenuItem("Edit Game", $GAME_MENU) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### Create all the child windows and hide them. $ADD_USER_SCREEN = GUICreate("Add User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) $Button1 = GUICtrlCreateButton("Button1", 168, 144, 75, 25, 0) GUISetState(@SW_HIDE) $DELETE_USER_SCREEN = GUICreate("Delete User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_USER_SCREEN = GUICreate("Edit User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $ADD_SYSTEM_SCREEN = GUICreate("Add System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $DELETE_SYSTEM_SCREEN = GUICreate("Delete System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_SYSTEM_SCREEN = GUICreate("Edit System", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $ADD_GAME_SCREEN = GUICreate("Add Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $DELETE_GAME_SCREEN = GUICreate("Delete Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) $EDIT_GAME_SCREEN = GUICreate("Edit Game", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) GUISetState(@SW_HIDE) #EndRegion ### While 1 $Msg = GUIGetMsg(1) $CTRLMsg = $Msg[0] $Win = $Msg[1] Switch $Msg Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $MAIN_SCREEN GUIDelete() Exit ; Check to see if a child window has requested to be closed Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_USER_SCREEN WinSetState("Add User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_USER_SCREEN WinSetState("Edit User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_USER_SCREEN WinSetState("Delete User","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_SYSTEM_SCREEN WinSetState("Add System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_SYSTEM_SCREEN WinSetState("Edit System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_SYSTEM_SCREEN WinSetState("Delete System","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_GAME_SCREEN WinSetState("Add Game","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $EDIT_GAME_SCREEN WinSetState("Edit Game","",@SW_HIDE) Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $DELETE_GAME_SCREEN WinSetState("Delete Game","",@SW_HIDE) ;Spawn the child windows when requested Case $CtrlMsg = $ADD_USER WinSetState("Add User","",@SW_SHOW) WinActivate("Add User") Case $CtrlMsg = $EDIT_USER WinSetState("Edit User","",@SW_SHOW) WinActivate("Edit User") Case $CtrlMsg = $DELETE_USER WinSetState("Delete User","",@SW_SHOW) WinActivate("Delete User") Case $CtrlMsg = $ADD_SYSTEM WinSetState("Add System","",@SW_SHOW) WinActivate("Add System") Case $CtrlMsg = $EDIT_SYSTEM WinSetState("Edit System","",@SW_SHOW) WinActivate("Edit System") Case $CtrlMsg = $DELETE_SYSTEM WinSetState("Delete System","",@SW_SHOW) WinActivate("Delete System") Case $CtrlMsg = $ADD_GAME WinSetState("Add Game","",@SW_SHOW) WinActivate("Add Game") Case $CtrlMsg = $EDIT_GAME WinSetState("Edit Game","",@SW_SHOW) WinActivate("Edit Game") Case $CtrlMsg = $DELETE_GAME WinSetState("Delete Game","",@SW_SHOW) WinActivate("Delete Game") Case $Button1 TEST() EndSwitch WEnd Exit Func TEST() MsgBox(0,"title","test") EndFunc Link to comment Share on other sites More sharing options...
gsglive Posted February 18, 2008 Share Posted February 18, 2008 Have you tried WinSetFocus? It is meant for automation, but it should work just as well with your child GUIs. -gsglive - gsglive Link to comment Share on other sites More sharing options...
eyegeegeewhy Posted February 18, 2008 Author Share Posted February 18, 2008 ive tried several things but none seem to work. All I want is a gui with several child windows accesible from a menu with buttons on each. Have i gone down the wrong route? Link to comment Share on other sites More sharing options...
Squirrely1 Posted February 19, 2008 Share Posted February 19, 2008 Maybe the function GUISwitch will help you - it changes the default GUI for use with other functions. Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
eyegeegeewhy Posted February 19, 2008 Author Share Posted February 19, 2008 Maybe the function GUISwitch will help you - it changes the default GUI for use with other functions.That was one of the options I was looking at but im unsure if I was making the switch at the right time (well i know i wasnt cause it still didnt work. Link to comment Share on other sites More sharing options...
MrFlibble Posted February 20, 2008 Share Posted February 20, 2008 Hi I am trying to create a GUI with multiple child windows. I have got the GUi working with the chilren. But am having trouble getting buttons on the child windows to do anything. Im not sure if I have gone about this the best way should i be using OnEvent? What i want is $button one to launch function test Code is below I have commented out the DB bits as they are not needed yet Use GUISetState instead, this worked fine for me. #include <GUIConstants.au3> $MAIN_SCREEN = GUICreate("GAMME_APP", 481, 336, 477, 432) $Menu = GUICtrlCreateMenu("&Menu") $USER_MENU = GUICtrlCreateMenu("User", $Menu) $ADD_USER = GUICtrlCreateMenuItem("Add User", $USER_MENU) GUISetState(@SW_SHOW) $ADD_USER_SCREEN = GUICreate("Add User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) $Button1 = GUICtrlCreateButton("Button1", 168, 144, 75, 25, 0) GUISetState(@SW_HIDE) While 1 $Msg = GUIGetMsg(1) $CTRLMsg = $Msg[0] $Win = $Msg[1] Select Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $MAIN_SCREEN Exit Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_USER_SCREEN GUISetState(@SW_SHOW, $MAIN_SCREEN) GUISetState(@SW_HIDE, $ADD_USER_SCREEN) Case $CtrlMsg = $ADD_USER GUISetState(@SW_HIDE, $MAIN_SCREEN) GUISetState(@SW_SHOW, $ADD_USER_SCREEN) Case $CtrlMsg = $Button1 TEST() EndSelect WEnd Func TEST() MsgBox(0, "title", "test") EndFunc ;==>TEST Link to comment Share on other sites More sharing options...
eyegeegeewhy Posted February 20, 2008 Author Share Posted February 20, 2008 Use GUISetState instead, this worked fine for me. #include <GUIConstants.au3> $MAIN_SCREEN = GUICreate("GAMME_APP", 481, 336, 477, 432) $Menu = GUICtrlCreateMenu("&Menu") $USER_MENU = GUICtrlCreateMenu("User", $Menu) $ADD_USER = GUICtrlCreateMenuItem("Add User", $USER_MENU) GUISetState(@SW_SHOW) $ADD_USER_SCREEN = GUICreate("Add User", 370, 397, 433, 158, -1, -1, $MAIN_SCREEN) $Button1 = GUICtrlCreateButton("Button1", 168, 144, 75, 25, 0) GUISetState(@SW_HIDE) While 1 $Msg = GUIGetMsg(1) $CTRLMsg = $Msg[0] $Win = $Msg[1] Select Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $MAIN_SCREEN Exit Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $ADD_USER_SCREEN GUISetState(@SW_SHOW, $MAIN_SCREEN) GUISetState(@SW_HIDE, $ADD_USER_SCREEN) Case $CtrlMsg = $ADD_USER GUISetState(@SW_HIDE, $MAIN_SCREEN) GUISetState(@SW_SHOW, $ADD_USER_SCREEN) Case $CtrlMsg = $Button1 TEST() EndSelect WEnd Func TEST() MsgBox(0, "title", "test") EndFunc ;==>TEST YOU my Sir are both a Scholer and a Gentleman. Thankyou 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