IvanCodin Posted January 11, 2009 Share Posted January 11, 2009 I have a script that I am unable to make work correctly. The Main GUI displays buttons I wish the user to see and works without issue. What I am trying to do is add a second GUI, new buttons etc. In the Main GUI I want to press a button to switch to the other GUI, In my script it is case button 12. When I switch between GUI windows if there is anything typed in <== My Notes ==> I want it to be move between both GUI windows and appear transparent. When I exit the script it send me to the second GUI. Do I need to combine the first and second case statements into one large one? CODE#Include <GUIConstantsEX.au3> #Include <Misc.au3> #include <Process.au3> ;Opt('GUIOnEventMode','1') #cs <================================================================================================= =======> Version Information 0.90.1 -> Initial version 0.90.2 -> Added Menu items 0.90.3 -> Add notes -> Add RAS IP address 0.90.8 -> use scriptdir -> Check My Notes and ask if they want to save it -> New Context menus To Do Verify successful RAS connection before ssh or telnet connection is attempted. <= Done After successful connection determine the Server RAS ip address and telnet or ssh to it automatically. Check My Note when exiting an if not empty ask them if they want to save it. ini file to buttons, Read these from an INI file toggle menus between two GUI windows. => cdr test application <================================================================================================= =======> #ce ; vars HotkeySet("^x", "_Bye") $my_version = "0.90.8" ; Applications we will use $treepad = "C:\Documents and Settings\cclausen\My Documents\- Tools\Treepad" $ccconsole = @ScriptDir & "\Console.exe" $vncviewer = @ScriptDir & "\UltraVNC\vncviewer.exe" $keepass = @ScriptDir & "\KeePass.exe" $stopwatch = @scriptdir & "\stopwtch.exe" $puttycm = @scriptdir & "\puttycm.exe" $putty = @scriptdir & "\putty.exe" If WinExists("My Tools") Then MsgBox(4096,"Info", "Only one copy of this application script can be run at once!!!" & @CRLF & @CRLF & " Program will now exit.", 6) Exit Else EndIf $MainForm = GUICreate("My Tools", 499, 447, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') ;GUISetState(@SW_SHOW) $Context_Menu = GUICtrlCreateContextMenu () $Item_1 = GUICtrlCreateMenuItem ("About", $Context_Menu) GUICtrlSetOnEvent ($Item_1, "_About") $Item_2 = GUICtrlCreateMenuItem ("Exit", $Context_Menu) GUICtrlSetOnEvent ($Item_2, "_Exit") GUICtrlCreateLabel("<== My Notes ==>",35,18) $cCommand = GUICtrlCreateEdit("", 32, 40, 337, 377) $Button0 = GUICtrlCreateButton("Copy My Notes", 392, 46, 89, 23, 0) $Button1 = GUICtrlCreateButton("RAS", 392, 77, 89, 23, 0) $Button2 = GUICtrlCreateButton("Putty", 392, 108, 89, 23, 0) $Button3 = GUICtrlCreateButton("Telnet", 392, 139, 89, 23, 0) $Button4 = GUICtrlCreateButton("VNC", 392, 170, 89, 23, 0) $Button5 = GUICtrlCreateButton("Console 2", 392, 201, 89, 23, 0) $Button6 = GUICtrlCreateButton("KeePass", 392, 232, 89, 23, 0) $Button7 = GUICtrlCreateButton("Timer", 392, 263, 89, 23, 0) $Button8 = GUICtrlCreateButton("CMD Prompt", 392, 294, 89, 23, 0) $Button9 = GUICtrlCreateButton("Ping", 392, 325, 89, 23, 0) $Button10 = GUICtrlCreateButton("Treepad", 392, 356, 89, 23, 0) $Button11 = GUICtrlCreateButton("Spare", 392, 387, 89, 23, 0) $Button12 = GUICtrlCreateButton("Second GUI", 392, 418, 89, 23, 0) ;While 1 ;$msg = GUIGetMsg() ;WEnd While 1 GUISetState(@SW_SHOW) $msg = GUIGetMsg() If $msg = $Item_2 or $msg = -3 or $msg = -1 Then ExitLoop Select Case $msg = $GUI_EVENT_CLOSE Exit ;ExitLoop Case $msg = $Button1 Run(@ScriptDir & "\RAS-Dial.exe") If @error Then SplashTextOn("Notice - Error", " Your RAS-Dial command failed." & @CRLF & "RAS-Dial.exe was not found." & @CRLF, 380,65) Sleep(3000) SplashOff() EndIf Case $msg = $Button2 Putty() Case $msg = $Button3 Telnet() Case $msg = $Button4 vnc() Case $msg = $Button5 Run($ccconsole) If @error Then SplashTextOn("Notice - Error", " Your console command failed." & @CRLF & "No console application was found." & @CRLF, 380,65) Sleep(3000) SplashOff() EndIf Case $msg = $Button6 Run($keepass) If @error Then SplashTextOn("Notice - Error", " Your KeePass application failed." & @CRLF & "No KeePass application was found." & @CRLF, 380,65) Sleep(3000) SplashOff() EndIf Case $msg = $Button7 Run($stopwatch) If @error Then SplashTextOn("Notice - Error", " Your stopwatch command failed." & @CRLF & "No stopwatch application was found." & @CRLF, 380,65) Sleep(3000) SplashOff() EndIf Case $msg = $Button8 Run("cmd") Case $msg = $Button9 Pinger() Case $msg = $Button10 Treepad() Case $msg = $Button11 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button12 GoToSecond() Case $msg = $Button0 ClipPut("") ; clear to prevent duplicate entries ClipPut(GuiCtrlRead($cCommand) & @CRLF) If (@Error ==1) Then Msgbox(0, "", "Unable to copy to the ClipBoard.") EndIf ;EndSelect Sleep (2000) EndSelect WEnd ; end main menu #cs Begin new window here with new button items #ce $SecondForm = GUICreate("My Tools", 499, 447, 270, 98) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') $Context_Menu = GUICtrlCreateContextMenu () $Item_1 = GUICtrlCreateMenuItem ("About", $Context_Menu) GUICtrlSetOnEvent ($Item_1, "_About") $Item_2 = GUICtrlCreateMenuItem ("Exit", $Context_Menu) GUICtrlSetOnEvent ($Item_2, "_Exit") GUISwitch ($SecondForm) GUISetState(@SW_SHOW, $SecondForm) GUICtrlCreateLabel("<== Second page ==>",35,18) $cCommand = GUICtrlCreateEdit("", 32, 40, 337, 377) $Button20 = GUICtrlCreateButton("Button 20", 392, 46, 89, 23, 0) $Button21 = GUICtrlCreateButton("Button 21", 392, 77, 89, 23, 0) $Button22 = GUICtrlCreateButton("Button 22", 392, 108, 89, 23, 0) $Button23 = GUICtrlCreateButton("Button 23", 392, 139, 89, 23, 0) $Button24 = GUICtrlCreateButton("Button 24", 392, 170, 89, 23, 0) $Button25 = GUICtrlCreateButton("Button 25", 392, 201, 89, 23, 0) $Button26 = GUICtrlCreateButton("Button 26", 392, 232, 89, 23, 0) $Button27 = GUICtrlCreateButton("Button 27", 392, 263, 89, 23, 0) $Button28 = GUICtrlCreateButton("Button 28", 392, 294, 89, 23, 0) $Button29 = GUICtrlCreateButton("Button 29", 392, 325, 89, 23, 0) $Button30 = GUICtrlCreateButton("Button 30", 392, 356, 89, 23, 0) $Button31 = GUICtrlCreateButton("Button 31", 392, 387, 89, 23, 0) $Button32 = GUICtrlCreateButton("Return to Main", 392, 418, 89, 23, 0) While 1 GUISetState(@SW_SHOW) $msg = GUIGetMsg() If $msg = $Item_2 or $msg = -3 or $msg = -1 Then ExitLoop Select Case $msg = $GUI_EVENT_CLOSE Exit ;ExitLoop Case $msg = $Button20 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button21 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button22 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button23 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button24 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button25 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button26 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button27 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button28 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button29 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button30 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button31 MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button32 GoToMain() ;MsgBox(4096,"Info", "Not yet implemented", 3) Case $msg = $Button0 ClipPut("") ; clear to prevent duplicate entries ClipPut(GuiCtrlRead($cCommand) & @CRLF) If (@Error ==1) Then Msgbox(0, "", "Unable to copy to the ClipBoard.") EndIf ;EndSelect Sleep (2000) EndSelect WEnd ; end main menu Func GoToMain() GUISwitch ($MainForm) GUISetState(@SW_SHOW) EndFunc Func GoToSecond() GUISwitch ($SecondForm) GUISetState(@SW_SHOW) EndFunc Func Telnet() $ip = InputBox("IP", "Enter IP to connect to", @IPAddress1) If (@Error ==1) Then Msgbox(0, "", "canceled.") return 0 EndIf run("telnet " & $ip) If @error Then SplashTextOn("Notice - Error", " Your telnet command failed." & @CRLF & "No telent command avaliable.", 380,65) Sleep(3000) SplashOff() EndIf EndFunc ; telnet Func PuttyCM() run($PuttyCM) If @error Then SplashTextOn("Notice - Error", " Your PuttyCM application failed." & @CRLF & "No PuttyCM application was found.", 380,65) Sleep(3000) SplashOff() EndIf EndFunc ; ==> PuttyCM Func Putty() $ssh = InputBox("IP", "Enter IP to connect to", @IPAddress1) If (@Error ==1) Then Msgbox(0, "", "Canceled.") return 0 EndIf run("putty " & $ssh) If @error Then SplashTextOn("Notice - Error", " Your putty command failed." & @CRLF & "No putty command avaliable.", 380,65) Sleep(3000) SplashOff() EndIf EndFunc ; ==> Putty Func vnc() $servername = InputBox("IP", "Enter IP to connect to", @IPAddress1) If (@Error ==1) Then Msgbox(0, "", "Canceled.") return 0 EndIf run($vncviewer & " " & $servername) If @error Then SplashTextOn("Notice - Error", " Your Ultravnc command failed." & @CRLF & "No UltraVNC command avaliable.", 380,65) Sleep(3000) SplashOff() EndIf EndFunc ; ==> vnc Func Treepad() ; run($treepad) ShellExecute ($treepad) If @error Then SplashTextOn("Notice - Error", " Treepad failed." & @CRLF & "No Treepad application avaliable.", 380,65) Sleep(3000) SplashOff() EndIf EndFunc ; ==> Treepad Func Pinger() $ip = InputBox("IP", "Enter IP address you wish to ping") If (@Error ==1) Then Msgbox(4096, "", "Canceled.") return 0 EndIf run("ping " & $ip) EndFunc ; ==> Pinger Func dbg($msg) DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg) EndFunc Func _About() MsgBox(0, "About", "My Tool Box " & $my_version, 4) EndFunc ; ==> _About Func _Bye() ;SoundPlay(@WindowsDir & "\media\tada.wav",1) MsgBox(0, "Bye", "Exiting program", 4) Exit EndFunc ;==> _Bye Func _Exit () ;$info = ClipGet() ;If clipboard is not empty do you want to save? if (GuiCtrlRead($cCommand)) == "" Then ; continue Else MsgBox(4096,"Info", "My Notes is not empty!!", 3) EndIf Exit EndFunc ; ==> _Exit When I switch the script to GUIOnEventMode 1, I want my ContextMenus to work, it breaks the buttons. I believe I need to resolve this before I can switch between the GUI windows. I have looked at the Help File and read the GUI reference - On Event Mode and am not able to resolve my problem. Any recommendations? CC Link to comment Share on other sites More sharing options...
Valuater Posted January 11, 2009 Share Posted January 11, 2009 1st... It's one or the other, you can not combine $msg = GUIGetMsg() and Opt('GUIOnEventMode','1') So, change the buttons to GUICtrlSetOnEvent ($Button0, "Function_Name") or remove all "OnEventMode" stuff 8) Link to comment Share on other sites More sharing options...
IvanCodin Posted January 11, 2009 Author Share Posted January 11, 2009 I can't get my Context Menus to work with setting the GUICtrlSetOnEvent to 1. Will they work if I use get GUI message and is there a preferred method you recommend I use? CC Link to comment Share on other sites More sharing options...
Valuater Posted January 11, 2009 Share Posted January 11, 2009 (edited) They will work either way, I changed the code to On Event and the contextmenu worked for me???? again use one or the other, I have made many scripts with both message or event modes 8) Edited January 11, 2009 by Valuater Link to comment Share on other sites More sharing options...
IvanCodin Posted January 11, 2009 Author Share Posted January 11, 2009 (edited) You mentioned you have used both methods in a script. What was the reason you used both? Is there any technical reason of just person preference? Thanks for youR response by the way!! CC Edited January 11, 2009 by IvanCodin 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