Raja Posted November 11, 2007 Share Posted November 11, 2007 Hi Looking forward to some help and learn what should have been the correct way to do this task. I am obviously doing something wrong as the OK button for $gui_2 does not respond in the code below, though it does work when the Func_1() is called on its own and not from within OK_1(). Same is true for the Close event. The code below is a sample of the actual code I am working on. Also, 1. What is the best way to unload/delete $gui_1 when loading $gui_2. I have used "GUIDelete($gui_1)" as the first line for each Case statement in $gui_2. 2. In $gui_2, on entering the password, is it possible to enable to get the focus on OK button so that {Enter} key can be pressed to click on OK button. Many thanks in advance. Raja expandcollapse popup#include <GUIConstants.au3> Opt("RunErrorsFatal", 0) Opt("GuiOnEventMode", 1) Opt("TrayIconDebug", 1) Dim $label_3 $gui_1 = GUICreate("My GUI", 480, 290, -1, -1, $WS_THICKFRAME) GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $gui_1) $Group_1 = GuiCtrlCreateGroup("", 30, 80, 415, 110) GUIStartGroup() $radio_1 = GuiCtrlCreateradio("Radio_1", 50, 115, 380, 20) $radio_2 = GuiCtrlCreateradio("Radio_2", 50, 150, 380, 20) GUICtrlCreateGroup("",-99,-99,1,1) $button_1 = GuiCtrlCreatebutton("OK", 250, 210, 90, 30) GUICtrlSetOnEvent($button_1, "OK_1") $button_2 = GuiCtrlCreatebutton("Cancel", 360, 210, 90, 30) GUICtrlSetOnEvent($button_2, "Close") GUISetState(@SW_SHOW) While 1 Sleep(300) WEnd Func OK_1() Select Case GUICtrlRead($radio_1) = $GUI_CHECKED GUIDelete($gui_1) Func_1() Case GUICtrlRead($radio_2) = $GUI_CHECKED GUIDelete($gui_1) Run(@WindowsDir & "\Notepad") Case Else Return EndSelect EndFunc Func Close() Exit EndFunc Func Func_1() $gui_2 = GUICreate("My GUI 2", 330, 240, -1, -1, $WS_THICKFRAME) GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $gui_2) GUICtrlCreateGroup("Please enter your windows login credentials.", 25, 20, 275, 120) GUICtrlCreatelabel("Username", 55, 60) $label_2 = GUICtrlCreateInput(@UserName, 140, 58, 120, 20) GUICtrlCreatelabel("Password", 55, 100) $label_3 = GUICtrlCreateInput("", 140, 98, 120, 20, $ES_PASSWORD) GUICtrlSetState(-1, $GUI_FOCUS) $button_3 = GUICtrlCreatebutton ("OK", 130, 160, 70, 30) GUICtrlSetOnEvent($button_3, "OK_2") GUISetState(@SW_SHOW) While 1 Sleep(300) WEnd EndFunc Func OK_2() $strPassword = GUICtrlRead($label_3, 1) If $strPassword = "" Then Return Exit EndFunc Link to comment Share on other sites More sharing options...
Nahuel Posted November 11, 2007 Share Posted November 11, 2007 There's no need for another loop after you create the second GUI. Remove that and you are good to go. Link to comment Share on other sites More sharing options...
Raja Posted November 11, 2007 Author Share Posted November 11, 2007 There's no need for another loop after you create the second GUI. Remove that and you are good to go.NahuelThank you so much!Much appreciate your help as I would have never been able to resolve this as I assumed the While/Wend loop is must for showing the GUI.Could you please also help with the other two questions I have.Thanks againRaja Link to comment Share on other sites More sharing options...
Nahuel Posted November 11, 2007 Share Posted November 11, 2007 1- Well... GUIDelete() is fine, I suppose. But it's better to use GUISetState() with flag @SW_HIDE if the window will be used later. When you want to show it back, use GUISetState with flag @SW_SHOW. Should be better than creating the GUI again. 2- If you use the style $BS_DEFPUSHBUTTON for the OK button, it will be the default button and will be pressed when you hit enter. Link to comment Share on other sites More sharing options...
Raja Posted November 11, 2007 Author Share Posted November 11, 2007 Once again, many thanks! I do really appreciate your help and the quick response, could not have asked for anything more. Cheers Raja 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