the123punch Posted October 31, 2008 Share Posted October 31, 2008 Hello, I am working on a script where I create one main window and from it after the user click on a button comes a child window. The child window has 2 buttons and will therefore need an event handler of its own. The main window has many buttons and has an event handler that is working great. I am using the GuiGetMsg() function to get the message from the window when there is a click on a button or anything like that on the main window. As you may know, this type of event handler is place in an infinite while loop which runs as long as the window is running. For the child window, I don't know how to add the event handlers for my 2 buttons. I tried adding them in that same while loop from the main window, but it seems that the event always fires at the child window button when I put it there, even if the child window has not been called yet. I am thinking maybe I need another while loop with the GuiGetMsg() function for the child window but that also doesn't seem to fix things properly. I get errors and it doesn't fire quite at the right time, because we have the presence of 2 infinite loops. Please find the code below for my main window event handler which works fine for the main window controls: CODEWhile 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $rdoAdmin deptEventListener(1) ;MsgBox(0, "Radio Button clicked", "Administration") Case $msg[0] = $rdoBiol deptEventListener(2) ;MsgBox(0, "Radio Button clicked", "Biology") Case $msg[0] = $rdoChem deptEventListener(3) ;MsgBox(0, "Radio Button clicked", "CombiChem") Case $msg[0] = $rdoIT deptEventListener(4) ;MsgBox(0, "Radio Button clicked", "IT") Case $msg[0] = $cmdClearForm clearForm() Case $msg[0] = $cmdCreateUser createUser() Case $msg[0] = $cmdSaveConfig saveConfig() Case $msg[0] = $cmdImportConfig importConfig() Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $biGUI ExitLoop ; Case $msg[0] = $cmdViewLog; And $msg[1] = getLogGUI();returns the log window handle (child window) ; viewLog() ; Case $msg[0] = getCmdCloseWin() And $msg[1] = getLogGUI();returns the log window handle(child window) ; closeLogWin() Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = getLogGUI();returns the log window handle(child window) closeLogWin() EndSelect WEnd The commented lines are what I want to do when the event fires from the child window, but it seems that as soon as I run my program the event handler stops there so there must be something wrong. Either the event of the child window is firing at the wrong time or there is just something wrong with my logic. Can anyone help me with this issue? How do we handle events coming from a child window?? Thanks. the123punch Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2008 Share Posted October 31, 2008 Not enough info here for me to help you. I would need the creation of the two GUI's with this loop and the UDF - getLogGUI. 8) Link to comment Share on other sites More sharing options...
the123punch Posted November 3, 2008 Author Share Posted November 3, 2008 Hi, TThis is the code you requested for the child window creation: CODE#include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> ;GUI variables $Window_Color = 0xffffff; Changing the default window color to white Dim $logGUI, $cmdViewLog, $cmdCloseWin ;window handle for the Logging GUI Dim $ELABlabel, $CDBlabel, $PCPlabel, $TELlabel, $BIRMAlabel ;labels Dim $ELABstatus, $CDBstatus, $PCPstatus, $BIRMAstatus, $TELstatus ;status labels Dim $requesterLabel Local $XPOS_INITIATE_LABELS = 25 Local $XPOS_STATUS_LABELS = 235 Local $DIAMONDS_POS = 10 Local $STATUSICON_POS = 395 Local $STATUSLABEL_WIDTH = 160 ;Function which will create the log GUI ;@param: $requester = Person who initiated the requesting of user creation Func createLogWindow($requester) ; GUI $winPos = WinGetPos($biGUI) $logGUI = GuiCreate("UCA Log", 450, 400, $winPos[0]+25, $winPos[1]+25, $WS_OVERLAPPEDWINDOW, 0, $biGui) GUISetState(@SW_DISABLE, $biGUI) GUISetState(@SW_SHOW, $logGUI) GUISetBkColor( $Window_Color) GuiSetIcon(@WindowsDir & "\NOTEPAD.EXE", 0) GUICtrlSetDefColor(0x05064A) ; LABELS GUICtrlCreateLabel("Creating users based on your selection", 20, 20,280) GUICtrlSetFont(-1,10,600,4) GuiCtrlCreatePic("logo.gif",300,333, 150,54) GUISwitch($logGUI) $requesterLabel = GUICtrlCreateLabel("Requester: " & $requester, 20, 50) GUICtrlSetColor($requesterLabel, 0x004D28) $cmdViewLog = GuiCtrlCreateButton("View Log", 25, 333, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White GUICtrlSetState($cmdViewLog, $GUI_DISABLE) $cmdCloseWin = GuiCtrlCreateButton("Close", 150, 333, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White GUICtrlSetState($cmdCloseWin, $GUI_DISABLE) ;Creating labels for the statuses ;$CDBstatus = GUICtrlCreateLabel("Requested for CDB Laval & Created for CDB Navigator!", 100, 140) ;GUICtrlSetState($CDBstatus, $GUI_HIDE) ;$BIRMAstatus = GUICtrlCreateLabel("Created!", 100, 170) ;GUICtrlSetState($BIRMAstatus, $GUI_HIDE) ;$PCPstatus = GUICtrlCreateLabel("Created!", 100, 210) ;GUICtrlSetState($PCPstatus, $GUI_HIDE) ;$TELstatus = GUICtrlCreateLabel("Created!", 100, 240) ;GUICtrlSetState($TELstatus, $GUI_HIDE) EndFunc ;Get method that returns the log GUI window handle Func getLogGUI() return $logGUI EndFunc ;Get method that returns the log GUI window handle Func getCmdViewLog() return $cmdViewLog EndFunc ;Function which will open the log file for reading Func viewLog() MsgBox(0,"", "LOG "); ;ShellExecute(@ScriptDir & "\uca_log.txt") EndFunc ;Function which will close the log window and give back the focus to the main window Func closeLogWin() GUIDelete($logGUI) GUISetState(@SW_ENABLE, $biGUI) GUISwitch($biGUI) WinActivate($biGUI) MsgBox(0,"TTOT", "CLOSE"); EndFunc Func afterLog() GUICtrlSetState($cmdViewLog, $GUI_ENABLE) GUICtrlSetState($cmdCloseWin, $GUI_ENABLE) ;~ While 1 ;~ $msg1 = GUIGetMsg(1) ;~ Case $msg1[0] = $cmdViewLog And $msg1[1] = $logGUI ;~ viewLog() ;~ Case $msg1[0] = $cmdCloseWin And $msg1[1] = $logGUI ;~ closeLogWin() ;~ ExitLoop ;~ WEnd EndFunc ;Get method that returns the log GUI window handle Func getCmdCloseWin() return $cmdCloseWin EndFunc ;Method that will add a diamond on the window ;@param: $xPos = horizontal position where to add the diamond. %yPos = vertical position where to add the diamond. Func addDiamond($xPos, $yPos) GuiCtrlCreatePic("diamond.gif",$xPos,$yPos, 10,13) EndFunc ;Method that will add a check mark on the window when called ;@param: $xPos = horizontal position where to add the check mark %yPos = vertical position where to add the check mark. Func addCheckIcon($xPos, $yPos) GuiCtrlCreatePic("check.gif",$xPos,$yPos, 20,25) EndFunc ;Method that will add an error red-X mark on the window ;@param: $xPos = horizontal position where to add the red-X mark. %yPos = vertical position where to add the red-X mark. Func addErrorIcon($xPos, $yPos) GuiCtrlCreatePic("error.gif",$xPos,$yPos, 20,25) EndFunc And this is the code for the creation of the main window with the loop for event handling: CODE;All the includes #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <UCA_EventListener.au3> #include <UCA_Log.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <adfunctions.au3> ;variable declarations $loginID = "" $sLoginID = "" $title="" $salutation="" $phoneExt="" ;GUI variables $Window_Color = 0xffffff; Changing the default window color to white ; GUI $biGUI = GuiCreate("Automation", 600, 450) GUISetBkColor( $Window_Color) GuiSetIcon(@SystemDir & "\netsh.exe", 0) GUICtrlSetDefColor(0x05064A) ; LABELS GUICtrlCreateLabel("Welcome to the application. " & @CRLF & "Please fill-in the required data or import and config file to start.", 20, 30) GuiCtrlCreatePic("logo.gif",430,20, 150,54) ;input boxes GUICtrlCreateLabel("Login", 20, 75) $txtLogin = GUICtrlCreateInput ( "", 60, 72,110, 22) GUICtrlSetLimit(-1, 8) GUICtrlCreateLabel("First Name", 20, 110) $txtFname = GUICtrlCreateInput ( "", 20, 125,150, 22) GUICtrlCreateLabel("Last Name", 20, 160) $txtLname = GUICtrlCreateInput ( "", 20, 175,150, 22) GUICtrlCreateLabel("Email address", 205, 110) $txtEmail = GUICtrlCreateInput ( "", 205, 125,150, 22) GUICtrlCreateLabel("Supervisor Login", 205, 160) $txtSLogin = GUICtrlCreateInput ( "", 205, 175,150, 22) GUICtrlSetLimit(-1, 8) ;GROUP WITH RADIO BUTTONS GuiCtrlCreateGroup("Department", 375, 110, 193, 90) $rdoAdmin = GuiCtrlCreateRadio("Administration", 380, 130, 85) ;GUICtrlSetOnEvent(-1, 'deptEventListener') GuiCtrlSetState(-1, $GUI_CHECKED) $rdoBiol = GuiCtrlCreateRadio("Biology", 380, 150, 85) ;GUICtrlSetOnEvent(-1, 'deptEventListener') $rdoChem = GuiCtrlCreateRadio("Chemistry", 480, 130, 70) ;GUICtrlSetOnEvent(-1, 'deptEventListener') $rdoIT = GuiCtrlCreateRadio("IT", 480, 150, 70) ;GUICtrlSetOnEvent(-1, 'deptEventListener') GUICtrlCreateGroup ("",-99,-99,1,1) ;close group ; PIC GuiCtrlCreatePic("line.gif",20,220, 546,6) ; CHECKBOX GuiCtrlCreateGroup("Accounts to be created", 20, 235, 550, 135) $chkCDB = GuiCtrlCreateCheckbox("Corporate DataBase (CDB)", 30, 255, 250) $chkELAB = GuiCtrlCreateCheckbox("Electronic Laboratory", 30, 275, 280) $chkELnB = GuiCtrlCreateCheckbox("Electronic Laboratory HR", 30, 295, 280) $chkBIRMA = GuiCtrlCreateCheckbox("BIR", 30, 315, 250) $chkPCP = GuiCtrlCreateCheckbox("PCP", 30, 335, 250) $chkAE = GuiCtrlCreateCheckbox("AE", 350, 255, 200) $chkTel = GuiCtrlCreateCheckbox("Telephone directory", 350, 275, 200) GUICtrlCreateGroup ("",-99,-99,1,1) ;close group deptEventListener(1) ; BUTTONS $cmdImportConfig = GuiCtrlCreateButton("Import Config File", 245, 73, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White $cmdSaveConfig = GuiCtrlCreateButton("Save Config File", 105, 395, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White $cmdCreateUser = GuiCtrlCreateButton("Create User", 245, 395, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White $cmdClearForm = GuiCtrlCreateButton("Clear Form", 385, 395, 111,25, $SS_SIMPLE ) GUICtrlSetColor(-1, 0x05064A) GUICtrlSetBkColor(-1, 0xffffff) ; White ; GUI MESSAGE LOOP GuiSetState() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $rdoAdmin deptEventListener(1) ;MsgBox(0, "Radio Button clicked", "Administration") Case $msg[0] = $rdoBiol deptEventListener(2) ;MsgBox(0, "Radio Button clicked", "Biology") Case $msg[0] = $rdoChem deptEventListener(3) ;MsgBox(0, "Radio Button clicked", "Chemistry") Case $msg[0] = $rdoIT deptEventListener(4) ;MsgBox(0, "Radio Button clicked", "IT") Case $msg[0] = $cmdClearForm clearForm() Case $msg[0] = $cmdCreateUser createUser() Case $msg[0] = $cmdSaveConfig saveConfig() Case $msg[0] = $cmdImportConfig importConfig() Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $biGUI ExitLoop ; Case $msg[0] = $cmdViewLog; And $msg[1] = getLogGUI() ; viewLog() ; Case $msg[0] = getCmdCloseWin() And $msg[1] = getLogGUI() ; closeLogWin() Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = getLogGUI() closeLogWin() EndSelect WEnd So the loop is at the very end of this codebox. Don't worry about the functions that are missing (like clearForm() or createUser() etc...) it is only the last part that isn't working. The commented lines in the loop are supposed to be for the child window. But it isn't working. When I uncomment those, the loop always stops at it as if the child window event constantly fires. If I create a loop in the child window, there will be 2 loops to handle and I don't think it is convenient to do and quite frankly I don't really know how to do that either. So if anyone could be of help, I would greatly appreciate the effort. Thanks. the123punch Link to comment Share on other sites More sharing options...
Valuater Posted November 3, 2008 Share Posted November 3, 2008 How come you have two different scripts with different includes if its a child? I do not understand. This should be all in one script using the same includes. I do not need any of the UDF's except the getLogGUI() and if there is one for the child GUI 8) Link to comment Share on other sites More sharing options...
the123punch Posted November 3, 2008 Author Share Posted November 3, 2008 I set it up that way because I have different UDFs for each window and it is also for script organization. getLogGui() is there in the first portion of my codebox if you checked it out. As I said, this is the way that I have done it and I am not totally an expert with AutoIt so if you know of a better or more organized way then it'll be great . Correct me if I'm wrong, but I dont think the fact that I have two different files for the two windows is what is causing me troubles... Thanks. the123punch 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