Sign in to follow this  
Followers 0
IvanCodin

Switch GUI Windows

5 posts in this topic

#1 ·  Posted (edited)

I am not able to have all three gui's displayed in my script. I created three gui's I want to display at various times. First Form, Second Form , and Third Form. Initially the first form is displayed which then gives me button to access the other forms. When I press the GUI button to open the Second from the First form is hidden and the second form is displayed. Same thing should happen for the third form. I can comment out either the Second or the Third form and my script works. I can not get all three to work. I have commented out the Second form in the script to test my code below. If I uncomment it the GUI is not displayed when the script is run. I know it must be somethong simple but I have been unable to figure it out. Below is my code with the second GUI comment out.

#include <IE.au3>
#include <GUIConstantsEX.au3>
#include <Misc.au3>
#include <Process.au3>
#Include <GuiEdit.au3>
;AutoItSetOption("MustDeclareVars", 1)
Opt('GUIOnEventMode',True)
;Opt("WinSearchChildren",1)
;MsgBox(0, "Info", @AutoitVersion,3)
#cs
    <===================================================================================================>
    Version Information
    0.91.0 -> Initial version
    0.91.1 -> Added capability to copy from clip board to GUI window
    0.91.2 -> Added thrid window and multiple clipboards 
            
    <========================================================================================================>
#ce
; vars
HotKeySet("^x", "_Bye")
$my_version = "0.91.2"
Global $Width = ('499')
Global $Height = ('447')

;Dim $hGUI1, $hGUI2, $hGUI3
; Applications we will use
$putty = @ScriptDir & "\putty.exe"

If _Singleton ("Ctools", 1 ) = 0 Then
    ; script is already running
    MsgBox(0, "Ctools", "Ctools is already running. Multiple copies cannot be run at once!")
    Exit
EndIf

; => Main Form
$hGUI1 = GUICreate("My Tools", $Width, $Height, 270, 98)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hGUI1)
; =>Context Menu MainFrom
$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  =====>", 115, 10)
; =>MainForm buttons
$Button01 = GUICtrlCreateButton("ClipBrd2Notes", 392, 15, 89, 23, 0)
GUICtrlSetOnEvent($Button01, "FrmClip1")
$cCommand1 = GUICtrlCreateEdit("", 20, 40, 365, 397)
$Button0 = GUICtrlCreateButton("Notes2ClipBrd", 392, 46, 89, 23, 0)
GUICtrlSetOnEvent($Button0,"MyClip1")
$Button1 = GUICtrlCreateButton("Spare", 392, 77, 89, 23, 0)
GUICtrlSetOnEvent($Button1, "Spare")
$Button2 = GUICtrlCreateButton("Spare", 392, 108, 89, 23, 0)
GUICtrlSetOnEvent($Button2, "Spare")
$Button3 = GUICtrlCreateButton("Spare", 392, 139, 89, 23, 0)
GUICtrlSetOnEvent($Button3, "Spare")
$Button4 = GUICtrlCreateButton("Spare", 392, 170, 89, 23, 0)
GUICtrlSetOnEvent($Button4, "Spare")
$Button5 = GUICtrlCreateButton("Spare", 392, 201, 89, 23, 0)
GUICtrlSetOnEvent($Button5, "Spare")
$Button6 = GUICtrlCreateButton("Spare", 392, 232, 89, 23, 0)
GUICtrlSetOnEvent($Button6, "Spare")
$Button7 = GUICtrlCreateButton("CMD prompt", 392, 263, 89, 23, 0)
GUICtrlSetOnEvent($Button7, "CMDPrompt")
$Button8 = GUICtrlCreateButton("Ping", 392, 294, 89, 23, 0)
GUICtrlSetOnEvent($Button8, "Pinger")
$Button9 = GUICtrlCreateButton("Telnet", 392, 325, 89, 23, 0)
GUICtrlSetOnEvent($Button9, "Telnet")
$Button10 = GUICtrlCreateButton("Putty", 392, 356, 89, 23, 0)
GUICtrlSetOnEvent($Button10, "Putty")
$Button11 = GUICtrlCreateButton("Tools-2", 392, 387, 89, 23, 0)
GUICtrlSetOnEvent($Button11, "SwitchGUI")
$Button12 = GUICtrlCreateButton("Tools-1", 392, 418, 89, 23, 0)
GUICtrlSetOnEvent($Button12, "SwitchGUI")

#cs If I comment this out the Third form works
; => Second Form
$hGUI2 = GUICreate("My Tools", $Width, $Height, 270, 98)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hGUI2)
; => Context Menus - SecondForm
$Context_Menu = GUICtrlCreateContextMenu()
$Item_1 = GUICtrlCreateMenuItem("About", $Context_Menu)
GUICtrlSetOnEvent ($Item_1,"_About")
$Item_2 = GUICtrlCreateMenuItem("Exit", $Context_Menu)
GUICtrlSetOnEvent ($Item_2,"_Exit")
GUICtrlCreateLabel("<======= Tools 2 =======>", 115, 10)
$cCommand2 = GUICtrlCreateEdit("", 20, 40, 365, 397)
$Button20 = GUICtrlCreateButton("Spare", 392, 46, 89, 23, 0)
GUICtrlSetOnEvent($Button20,"Spare")
; => SecondForm Buttons
$Button21 = GUICtrlCreateButton("Spare", 392, 77, 89, 23, 0)
GUICtrlSetOnEvent($Button21,"Spare")
$Button22 = GUICtrlCreateButton("Spare", 392, 108, 89, 23, 0)
GUICtrlSetOnEvent($Button22, "Spare")
$Button23 = GUICtrlCreateButton("Spare", 392, 139, 89, 23, 0)
GUICtrlSetOnEvent($Button23, "Spare")
$Button24 = GUICtrlCreateButton("Spare", 392, 170, 89, 23, 0)
GUICtrlSetOnEvent($Button24, "Spare")
$Button25 = GUICtrlCreateButton("Spare", 392, 201, 89, 23, 0)
GUICtrlSetOnEvent($Button25, "Spare")
$Button26 = GUICtrlCreateButton("Spare", 392, 232, 89, 23, 0)
GUICtrlSetOnEvent($Button26, "Spare")
$Button27 = GUICtrlCreateButton("Spare", 392, 263, 89, 23, 0)
GUICtrlSetOnEvent($Button27, "Spare")
$Button28 = GUICtrlCreateButton("Spare", 392, 294, 89, 23, 0)
GUICtrlSetOnEvent($Button28, "Spare")
$Button29 = GUICtrlCreateButton("Spare", 392, 325, 89, 23, 0)
GUICtrlSetOnEvent($Button29, "Spare")
$Button30 = GUICtrlCreateButton("Spare", 392, 356, 89, 23, 0)
GUICtrlSetOnEvent($Button30, "Spare")
$Button31 = GUICtrlCreateButton("Spare", 392, 387, 89, 23, 0)
GUICtrlSetOnEvent($Button31, "Spare")
$Button32 = GUICtrlCreateButton("Return to Main", 392, 418, 89, 23, 0)
GUICtrlSetOnEvent($Button32, "SwitchGUI")
;GUISetState(@SW_SHOW, $hGUI1)
#ce

; => Third Form
$hGUI3 = GUICreate("My Tools", $Width, $Height, 270, 98)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hGUI3)
; => Context Menus - ThirdForm
$Context_Menu = GUICtrlCreateContextMenu()
$Item_1 = GUICtrlCreateMenuItem("About", $Context_Menu)
GUICtrlSetOnEvent ($Item_1,"_About")
$Item_2 = GUICtrlCreateMenuItem("Exit", $Context_Menu)
GUICtrlSetOnEvent ($Item_2,"_Exit")
GUICtrlCreateLabel("<======= Tools 2 =======>", 115, 10)
; => ThirdForm Buttons
$cCommand3 = GUICtrlCreateEdit("", 20, 40, 365, 397)
$Button40 = GUICtrlCreateButton("Spare", 392, 46, 89, 23, 0)
GUICtrlSetOnEvent($Button40,"Spare")
$Button41 = GUICtrlCreateButton("Spare", 392, 77, 89, 23, 0)
GUICtrlSetOnEvent($Button41,"Spare")
$Button42 = GUICtrlCreateButton("Spare", 392, 108, 89, 23, 0)
GUICtrlSetOnEvent($Button42, "Spare")
$Button43 = GUICtrlCreateButton("Spare", 392, 139, 89, 23, 0)
GUICtrlSetOnEvent($Button43, "Spare")
$Button44 = GUICtrlCreateButton("Spare", 392, 170, 89, 23, 0)
GUICtrlSetOnEvent($Button44, "Spare")
$Button45 = GUICtrlCreateButton("Spare", 392, 201, 89, 23, 0)
GUICtrlSetOnEvent($Button45, "Spare")
$Button46 = GUICtrlCreateButton("Spare", 392, 232, 89, 23, 0)
GUICtrlSetOnEvent($Button46, "Spare")
$Button47 = GUICtrlCreateButton("Spare", 392, 263, 89, 23, 0)
GUICtrlSetOnEvent($Button47, "Spare")
$Button48 = GUICtrlCreateButton("Spare", 392, 294, 89, 23, 0)
GUICtrlSetOnEvent($Button48, "Spare")
$Button49 = GUICtrlCreateButton("Spare", 392, 325, 89, 23, 0)
GUICtrlSetOnEvent($Button49, "Spare")
$Button50 = GUICtrlCreateButton("Spare", 392, 356, 89, 23, 0)
GUICtrlSetOnEvent($Button50, "Spare")
$Button51 = GUICtrlCreateButton("Spare", 392, 387, 89, 23, 0)
GUICtrlSetOnEvent($Button51, "Spare")
$Button52 = GUICtrlCreateButton("Return to Main", 392, 418, 89, 23, 0)
GUICtrlSetOnEvent($Button52, "SwitchGUI")
GUISetState(@SW_SHOW, $hGUI1)




While 1
    $msg = GUIGetMsg()
    If $msg = $Item_2 Or $msg = -3 Or $msg = -1 Then
        ExitLoop
    EndIf
    Sleep(20) ; Idle around
WEnd


Func SwitchGUI()
    Switch @GUI_CtrlId
        Case $Button11 ; Main Form to Third Form
            $Pos = WinGetPos($hGUI1)
            WinMove($hGUI3, "", $Pos[0], $Pos[1])
            GUISetState(@SW_Hide, $hGUI1)
            GUISetState(@SW_SHOW, $hGUI3)
        ;Case $Button12 ; Main Form to Second Form
        ;   $Pos = WinGetPos($hGUI1)
        ;   WinMove($hGUI2, "", $Pos[0], $Pos[1])
        ;   GUISetState(@SW_Hide, $hGUI1)
        ;   GUISetState(@SW_SHOW, $hGUI2)
        ;Case $Button32 ; Second Form Return to Main
        ;   $Pos = WinGetPos($hGUI2)
        ;   WinMove($hGUI1, "", $Pos[0], $Pos[1])
        ;   GUISetState(@SW_Hide, $hGUI2)
        ;   GUISetState(@SW_SHOW, $hGUI1)
        Case $Button52 ; Third Form Return to Main
            $Pos = WinGetPos($hGUI3)
            WinMove($hGUI1, "", $Pos[0], $Pos[1])
            GUISetState(@SW_Hide, $hGUI3)
            GUISetState(@SW_SHOW, $hGUI1)
        Case Else
            GUISetState(@SW_Hide, $hGUi3)
        ;   GUISetState(@SW_Hide, $hGUi2)
            GUISetState(@SW_SHOW, $hGUI1)
        EndSwitch
EndFunc
    
Func CmdPrompt()
    Run("cmd")
EndFunc ;==> Cmdprompt

Func Telnet()
    $ip = InputBox("IP", "Enter IP to connect to")
    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 Putty()
    $ssh = InputBox("IP", "Enter IP to connect to", '' )
    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 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 Spare()
    MsgBox(4096, "Info", "Not yet implemented", 3)
EndFunc ;==> Spare

Func MyClip1()
    ClipPut("") ; clear to prevent duplicate entries
            ClipPut(GUICtrlRead($cCommand1) & @CRLF)
            If (@error == 1) Then
                MsgBox(0, "", "Unable to copy to the ClipBoard.")
            EndIf
            ;EndSelect
            Sleep(2000)
EndFunc ; => Myclip1

Func FrmClip1()
    $bak = ClipGet()
    _GUICtrlEdit_AppendText($cCommand1, $bak)
    $bak1 = GUICtrlRead($Ccommand1)
EndFunc ; => Frmclip1

#cs
Func MyClip3()
    ClipPut("") ; clear to prevent duplicate entries
            ClipPut(GUICtrlRead($cCommand3) & @CRLF)
            If (@error == 1) Then
                MsgBox(0, "", "Unable to copy to the ClipBoard.")
            EndIf
            ;EndSelect
            Sleep(2000)
        EndFunc ; => Myclip3
        
Func MyClip4()
    ClipPut("") ; clear to prevent duplicate entries
            ClipPut(GUICtrlRead($cCommand4) & @CRLF)
            If (@error == 1) Then
                MsgBox(0, "", "Unable to copy to the ClipBoard.")
            EndIf
            ;EndSelect
            Sleep(2000)
EndFunc ; => Myclip4


Func MyClip5()
    ClipPut("") ; clear to prevent duplicate entries
            ClipPut(GUICtrlRead($cCommand5) & @CRLF)
            If (@error == 1) Then
                MsgBox(0, "", "Unable to copy to the ClipBoard.")
            EndIf
            ;EndSelect
            Sleep(2000)
EndFunc ; => Myclip5

Func MyClip6()
    ClipPut("") ; clear to prevent duplicate entries
            ClipPut(GUICtrlRead($cCommand6) & @CRLF)
            If (@error == 1) Then
                MsgBox(0, "", "Unable to copy to the ClipBoard.")
            EndIf
            ;EndSelect
            Sleep(2000)
EndFunc ; => Myclip6
#ce
Func dbg($msg)
    DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc   ;==>dbg

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()
    GUIDelete($hGUI1)
    ;GUIDelete($hGUI2)
    GUIDelete($hGUI3)
    Exit
EndFunc   ;==>_Exit

I would really appreciate you help. Hopefully it's something really simple I missed and my code is not all screwed up.

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites



I think this is what you need GUISwitch() Never used it so im not sure.

Share this post


Link to post
Share on other sites

I looked in the Help Menu. I still don't understand why two GUI's work but three break the script. I'll keep looking at the Help file.

The way I read the Help file my script should work. I changed my script to use on event mode and delete the gui when I switch to the other.

CC

Share this post


Link to post
Share on other sites

It works fine for me if I uncomment the needed sections. (GUI2 creation and button handling in the SwitchGUI function).

A couple of notes though:

- GUI's 2 and 3 look exactly the same because they have the same label: "<======= Tools 2 =======>"

- GUIGetMsg always returns 0 because you're using event mode. All you need is a sleep in that while loop.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Thanks. I correct My Tools 2 to My Tools 3. Is the sleep you are refering to in the SwitchGUI function?

CC

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0