Jump to content

Recommended Posts

Posted (edited)

I have a script that was using Message Mode which I changed to OnEvent mode. I am not able to figure out the logic that displays my GUI when the script runs. I know it must be something very simple but it has eluded me as to how it should works. I read the ReadMe and modified my version to mimic the Help File as closely as I could but it still won't work. Can you pint me to me error in logic?

CODE

#include <GUIConstantsEX.au3>

#include <Misc.au3>

#include <Process.au3>

Opt('GUIOnEventMode','1')

; vars

HotKeySet("^x", "_Bye")

$my_version = "0.90.8"

; Applications we will use

$treepad = "C:\Documents and Settings\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

MsgBox(4096, "TS", "Begin")

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")

$MainForm = GUICreate("My Tools", 499, 447, 270, 98)

GUICtrlCreateLabel("<== My Notes ==>", 35, 18)

$cCommand = GUICtrlCreateEdit("", 32, 40, 337, 377)

$Button0 = GUICtrlCreateButton("Copy My Notes", 392, 46, 89, 23, 0)

GUICtrlSetOnEvent($Button0, "MyClip")

$Button1 = GUICtrlCreateButton("RAS", 392, 77, 89, 23, 0)

GUICtrlSetOnEvent($Button1, "RasDial")

$Button2 = GUICtrlCreateButton("Putty", 392, 108, 89, 23, 0)

GUICtrlSetOnEvent($Button2, "Putty")

$Button3 = GUICtrlCreateButton("Telnet", 392, 139, 89, 23, 0)

GUICtrlSetOnEvent($Button3, "Telnet")

$Button4 = GUICtrlCreateButton("VNC", 392, 170, 89, 23, 0)

GUICtrlSetOnEvent($Button4, "vnc")

$Button5 = GUICtrlCreateButton("Console 2", 392, 201, 89, 23, 0)

GUICtrlSetOnEvent($Button5, "Console2")

$Button6 = GUICtrlCreateButton("KeePass", 392, 232, 89, 23, 0)

GUICtrlSetOnEvent($Button6, "KeePass")

$Button7 = GUICtrlCreateButton("Timer", 392, 263, 89, 23, 0)

GUICtrlSetOnEvent($Button7, "Timer")

$Button8 = GUICtrlCreateButton("CMD Prompt", 392, 294, 89, 23, 0)

GUICtrlSetOnEvent($Button8, "Cmdprompt")

$Button9 = GUICtrlCreateButton("Ping", 392, 325, 89, 23, 0)

GUICtrlSetOnEvent($Button9, "Pinger")

$Button10 = GUICtrlCreateButton("Treepad", 392, 356, 89, 23, 0)

GUICtrlSetOnEvent($Button10, "Treepad")

$Button11 = GUICtrlCreateButton("Spare", 392, 387, 89, 23, 0)

GUICtrlSetOnEvent($Button11, "Spare")

$Button12 = GUICtrlCreateButton("More", 392, 418, 89, 23, 0)

GUICtrlSetOnEvent($Button12, "SecondGUI")

$SecondForm = GUICreate("My Tools", 499, 447, 270, 98)

GUICtrlCreateLabel("<== Second page ==>", 35, 18)

$cCommand2 = GUICtrlCreateEdit("", 32, 40, 337, 377)

$Button20 = GUICtrlCreateButton("Copy My Notes", 392, 46, 89, 23, 0)

GUICtrlSetOnEvent($Button20, "Spare")

$Button21 = GUICtrlCreateButton("Button 21", 392, 77, 89, 23, 0)

GUICtrlSetOnEvent($Button21, "Spare")

$Button22 = GUICtrlCreateButton("Button 22", 392, 108, 89, 23, 0)

GUICtrlSetOnEvent($Button22, "Spare")

$Button23 = GUICtrlCreateButton("Button 23", 392, 139, 89, 23, 0)

GUICtrlSetOnEvent($Button23, "Spare")

$Button24 = GUICtrlCreateButton("Button 24", 392, 170, 89, 23, 0)

GUICtrlSetOnEvent($Button24, "Spare")

$Button25 = GUICtrlCreateButton("Button 25", 392, 201, 89, 23, 0)

GUICtrlSetOnEvent($Button25, "Spare")

$Button26 = GUICtrlCreateButton("Button 26", 392, 232, 89, 23, 0)

GUICtrlSetOnEvent($Button26, "Spare")

$Button27 = GUICtrlCreateButton("Button 27", 392, 263, 89, 23, 0)

GUICtrlSetOnEvent($Button27, "Spare")

$Button28 = GUICtrlCreateButton("Button 28", 392, 294, 89, 23, 0)

GUICtrlSetOnEvent($Button28, "Spare")

$Button29 = GUICtrlCreateButton("Button 29", 392, 325, 89, 23, 0)

GUICtrlSetOnEvent($Button29, "Spare")

$Button30 = GUICtrlCreateButton("Button 30", 392, 356, 89, 23, 0)

GUICtrlSetOnEvent($Button30, "Spare")

$Button31 = GUICtrlCreateButton("Button 31", 392, 387, 89, 23, 0)

GUICtrlSetOnEvent($Button31, "Spare")

$Button32 = GUICtrlCreateButton("Return to Main", 392, 418, 89, 23, 0)

GUICtrlSetOnEvent($Button32, "ReturnMainGUI")

#cs

I tried many versions of this and couldn't find the right combination.

While 1

MsgBox(4096, "TS", "GUI is shown with guisetstate and mainform")

;MainGUI(); GUISetState(@SW_SHOW, $MainForm)

$msg = GUIGetMsg()

MsgBox(4096, "TS", "Gui is deleted.")

If $msg = $Item_2 or $msg = -3 or $msg = -1 Then

ExitLoop

EndIf

MsgBox(4096, "TS", "End Endif Begin Select")

Select

Case $msg = $GUI_EVENT_Close

Exit

; exitloop

Sleep (200)

MsgBox(4096, "TS", "End Select ")

EndSelect

WEnd

#ce

GUISwitch($MainForm)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

If $msg = $Item_2 or $msg = -3 or $msg = -1 Then

ExitLoop

EndIf

Sleep(1000) ; Idle around

WEnd

Func MainGUI()

GUISetState(@SW_SHOW, $MainForm)

EndFunc ; End Main

Func SecondGUI()

$Pos = WinGetPos($MainForm)

WinMove($SecondForm, "", $Pos[0], $Pos[1])

GUISetState(@SW_Hide, $MainForm)

GUISetState(@SW_SHOW, $SecondForm)

; $msg2 = GUIGetMsg()

EndFunc ;==>Second

Func ReturnMainGUI()

GUISetState(@SW_Hide, $SecondForm)

GUISetState(@SW_SHOW, $MainForm)

EndFunc ; End ReturnMain

Func CmdPrompt()

Run("cmd")

EndFunc ; End Cmdprompt

Func Timer()

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

EndFunc ; Emd Timer

Func KeePass()

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

EndFunc ; End KeePass

Func RasDial()

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

EndFunc ; =End RasDial

Func Console2()

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

EndFunc ; End Console2

Func MyClip()

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)

EndFunc ; => End Myclip

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 Spare()

MsgBox(4096, "Info", "Not yet implemented", 3)

EndFunc ; End Spare

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()

;$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

Thanks

CC

Edited by IvanCodin
Posted

Thanks for the help! I looked at your changes and learned several things. I didn't know the Context Menus weren't Global. Now that I know this I added them the the SecondForm, it didn't use them either. Brings up a new question.

Is there way way to make all GUI with Global Context Menu's so all GUI windows can use them? I define them once and all GUI Forms use them?

I looked in the Help File and see references to Global variables but nothing like this.

CC

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
×
×
  • Create New...