Jump to content

error if you exit


Swift
 Share

Recommended Posts

i have this script...that will run in the background...and if you click: run on the tray icon...then it opens a input box...but if you clicked the wrong thing...you wanna close it right...but when you do...you get an error...saying it cant run it...because theres nothing in the box...but if you exit it...then it closes the box...and doesnt do ANYTHING else..

Case $trayrun
            $runit = InputBox("Run", "Run:")
            If $GUI_EVENT_CLOSE Then Exit
            Else
            Run($runit)
Link to comment
Share on other sites

i have this script...that will run in the background...and if you click: run on the tray icon...then it opens a input box...but if you clicked the wrong thing...you wanna close it right...but when you do...you get an error...saying it cant run it...because theres nothing in the box...but if you exit it...then it closes the box...and doesnt do ANYTHING else..

Case $trayrun
            $runit = InputBox("Run", "Run:")
            If $GUI_EVENT_CLOSE Then Exit
            Else
            Run($runit)
You should check @error after InputBox returns to see if the string is valid. $GUI_EVENT_CLOSE is a constant so the if statement doesn't make any sense to me.

Maybe this would be better.

$runit = InputBox("Run", "Run:")
Switch @error
   Case 1;Cancel or Close clicked
              ;do something
   Case 0
        if FileExists($runit) then Run($runit)
EndSwitch
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

ehh....how would that work...it makes no sence to me...i just want something...if you exit it then it closes...not that :D

thanks for the fast reply

full script..

#include <GUIConstants.au3>
#include "ModernMenu.au3"

#NoTrayIcon

GUISetState()

; Only balloon click msg should be registered for this icon
$nTrayIcon1     = _TrayIconCreate("Tools", "shell32.dll", 12, "MyTrayTipCallBack", $NIN_BALLOONUSERCLICK)
_TrayIconSetClick(-1, 16)

$MenuMenu       = _TrayCreateMenu(-1, "Menu")
_TrayItemSetIcon(-1, "", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)
$TrayAdvanced   = _TrayCreateItem(-1, "Modern", $MenuMenu, -1, 1)
_TrayItemSetIcon(-1, "", 0)
GUICtrlSetState(-1, $GUI_CHECKED)
$TraySimple     = _TrayCreateItem(-1, "Classic", $MenuMenu, -1, 1)
_TrayItemSetIcon(-1, "", 0)

$MenuLang       =  _TrayCreateMenu(-1, "Language")
_TrayItemSetIcon(-1, "", 0)
$LangEng        = _TrayCreateItem(-1, "English", $MenuLang)
_TrayItemSetIcon(-1, "Flags\uk.ico", 0)
$LangGer        = _TrayCreateItem(-1, "Deutsch", $MenuLang)
_TrayItemSetIcon(-1, "Flags\germany.ico", 0)
$LangRus        = _TrayCreateItem(-1, "Российская", $MenuLang)
_TrayItemSetIcon(-1, "Flags\russia.ico", 0)
$LangAra        = _TrayCreateItem(-1, "العربي", $MenuLang)
_TrayItemSetIcon(-1, "Flags\uae.ico", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)

$MenuDrives     = _TrayCreateMenu(-1, "Driveinfo")
_TrayItemSetIcon(-1, "shell32.dll", 8)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0); Force changing to ownerdrawn sometimes needed, i.e. in mixed menu
$MenuTools      = _TrayCreateMenu(-1, "Tools")
_TrayItemSetIcon(-1, "shell32.dll", 19)
$TrayCalc       = _TrayCreateItem(-1, "Calculator", $MenuTools)
_TrayItemSetIcon(-1, "calc.exe", 0)
$TrayCMD        = _TrayCreateItem(-1, "CMD", $MenuTools)
_TrayItemSetIcon(-1, "cmd.exe", 0)
$TrayNotepad    = _TrayCreateItem(-1, "Notepad", $MenuTools)
_TrayItemSetIcon(-1, "notepad.exe", 0)
$TrayRegedit    = _TrayCreateItem(-1, "Regedit", $MenuTools)
_TrayItemSetIcon(-1, "regedit.exe", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)

$TrayHelp       = _TrayCreateItem(-1, "Help")
GUICtrlSetState($TrayHelp, $GUI_DEFBUTTON)
_TrayItemSetIcon(-1, "shell32.dll", 23)
$TrayRun        = _TrayCreateItem(-1, "Run")
_TrayItemSetIcon(-1, "shell32.dll", 24)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)
$TrayExit       = _TrayCreateItem(-1, "Exit")
_TrayItemSetIcon(-1, "shell32.dll", 27)

_TrayCreateItem(-1, "Free Space:", $MenuDrives)
_TrayCreateItem(-1, "", $MenuDrives)
$arDrives = DriveGetDrive("FIXED")
For $i = 1 To $arDrives[0]
    _TrayCreateItem(-1, StringUpper($arDrives[$i]) & " -> " & _
        StringFormat("%.2f GB", DriveSpaceFree($arDrives[$i])), $MenuDrives)
Next

; WM_MEASUREITEM and WM_DRAWITEM are registered in 
; "ModernMenu.au3" so they don"t need to registered here
; Also OnAutoItExit() is in "ModernMenu.au3" to cleanup the
; menu imagelist and font

Dim $nTrayIcon2 = 0

; Create an icon which demonstrates how to use click event - see the function 'MyTrayTipCallBack'
Dim $nTrayIcon3 = _TrayIconCreate("Click me", "shell32.dll", 15, "MyTrayTipCallBack")

; Main GUI Loop

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $GUI_EVENT_CLOSE, $TrayExit
            ExitLoop
        Case $traycmd
            Run("CMD")
        Case $trayregedit
            Run("regedit.exe")
        Case $trayrun
            $trayrunbox = InputBox("Run", "Run:")
            Run($trayrunbox)
            
        Case $TrayAdvanced, $TraySimple
            If BitAnd(GUICtrlRead($TraySimple), $GUI_CHECKED) Then
                GUICtrlSetState($TraySimple, $GUI_UNCHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_CHECKED)
                $bUseAdvTrayMenu = TRUE
            Else
                GUICtrlSetState($TraySimple, $GUI_CHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_UNCHECKED)
                $bUseAdvTrayMenu = FALSE
            EndIf
            
        Case $TrayHelp
            If $nTrayIcon2 = 0 Then
                $nTrayIcon2 = _TrayIconCreate("New message", "shell32.dll", 13, "MyTrayTipCallBack")
            Else
                _TrayIconSetState($nTrayIcon2, 1)
            EndIf
            
            _TrayTip($nTrayIcon2, "New message", "A new message has arrived." & @CRLF & "Please click here to read...", 15, $NIIF_INFO)                         
        Case $trayrun
            $runit = InputBox("Run", "Run:")
            Run($runit)
    EndSwitch
WEnd

_TrayIconDelete($nTrayIcon1)
_TrayIconDelete($nTrayIcon3)

If $nTrayIcon2 > 0 Then _TrayIconDelete($nTrayIcon2)

Exit


Func MyTrayTipCallBack($nID, $nMsg)
    Switch $nID
        Case $nTrayIcon2
            Switch $nMsg
                Case $NIN_BALLOONUSERCLICK, $NIN_BALLOONTIMEOUT
                    If $nMsg = $NIN_BALLOONUSERCLICK Then MsgBox(64, "Help!", "This Is A Simple Sample"&@CRLF&"Of Color Edit")
                    _TrayIconSetState($nTrayIcon2, 2)
            EndSwitch
            
        Case $nTrayIcon3
            Switch $nMsg
    ;;; Case $WM_LBUTTONDOWN
            ; Put your stuff here
    ;;; case $WM_LBUTTONUP
            ; Put your stuff here; One click and double click to put together is difficult
                case $WM_LBUTTONDBLCLK
                    MsgBox(0, "Info", "You left double clicked on TrayIcon3.")
                    GUISetState(@SW_RESTORE, $hMainGUI); Restore/put focus back to our main GUI
    ;;; case $WM_RBUTTONDOWN
            ; Put your stuff here
                case $WM_RBUTTONUP
                    MsgBox(0, "Info", "You right clicked on TrayIcon3.")
                ; Restore/put focus back to our main GUI
    ;;; case $WM_RBUTTONDBLCLK
            ; Put your stuff here
    ;;; case $WM_MOUSEMOVE
            ; Put your stuff here
            EndSwitch
    EndSwitch
EndFunc
Edited by Swift
Link to comment
Share on other sites

ehh....how would that work...it makes no sence to me...i just want something...if you exit it then it closes...not that :D

thanks for the fast reply

full script..

#include <GUIConstants.au3>
#include "ModernMenu.au3"

#NoTrayIcon

GUISetState()

; Only balloon click msg should be registered for this icon
$nTrayIcon1     = _TrayIconCreate("Tools", "shell32.dll", 12, "MyTrayTipCallBack", $NIN_BALLOONUSERCLICK)
_TrayIconSetClick(-1, 16)

$MenuMenu       = _TrayCreateMenu(-1, "Menu")
_TrayItemSetIcon(-1, "", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)
$TrayAdvanced   = _TrayCreateItem(-1, "Modern", $MenuMenu, -1, 1)
_TrayItemSetIcon(-1, "", 0)
GUICtrlSetState(-1, $GUI_CHECKED)
$TraySimple     = _TrayCreateItem(-1, "Classic", $MenuMenu, -1, 1)
_TrayItemSetIcon(-1, "", 0)

$MenuLang       =  _TrayCreateMenu(-1, "Language")
_TrayItemSetIcon(-1, "", 0)
$LangEng        = _TrayCreateItem(-1, "English", $MenuLang)
_TrayItemSetIcon(-1, "Flags\uk.ico", 0)
$LangGer        = _TrayCreateItem(-1, "Deutsch", $MenuLang)
_TrayItemSetIcon(-1, "Flags\germany.ico", 0)
$LangRus        = _TrayCreateItem(-1, "Российская", $MenuLang)
_TrayItemSetIcon(-1, "Flags\russia.ico", 0)
$LangAra        = _TrayCreateItem(-1, "العربي", $MenuLang)
_TrayItemSetIcon(-1, "Flags\uae.ico", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)

$MenuDrives     = _TrayCreateMenu(-1, "Driveinfo")
_TrayItemSetIcon(-1, "shell32.dll", 8)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0); Force changing to ownerdrawn sometimes needed, i.e. in mixed menu
$MenuTools      = _TrayCreateMenu(-1, "Tools")
_TrayItemSetIcon(-1, "shell32.dll", 19)
$TrayCalc       = _TrayCreateItem(-1, "Calculator", $MenuTools)
_TrayItemSetIcon(-1, "calc.exe", 0)
$TrayCMD        = _TrayCreateItem(-1, "CMD", $MenuTools)
_TrayItemSetIcon(-1, "cmd.exe", 0)
$TrayNotepad    = _TrayCreateItem(-1, "Notepad", $MenuTools)
_TrayItemSetIcon(-1, "notepad.exe", 0)
$TrayRegedit    = _TrayCreateItem(-1, "Regedit", $MenuTools)
_TrayItemSetIcon(-1, "regedit.exe", 0)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)

$TrayHelp       = _TrayCreateItem(-1, "Help")
GUICtrlSetState($TrayHelp, $GUI_DEFBUTTON)
_TrayItemSetIcon(-1, "shell32.dll", 23)
$TrayRun        = _TrayCreateItem(-1, "Run")
_TrayItemSetIcon(-1, "shell32.dll", 24)
_TrayCreateItem(-1, "")
_TrayItemSetIcon(-1, "", 0)
$TrayExit       = _TrayCreateItem(-1, "Exit")
_TrayItemSetIcon(-1, "shell32.dll", 27)

_TrayCreateItem(-1, "Free Space:", $MenuDrives)
_TrayCreateItem(-1, "", $MenuDrives)
$arDrives = DriveGetDrive("FIXED")
For $i = 1 To $arDrives[0]
    _TrayCreateItem(-1, StringUpper($arDrives[$i]) & " -> " & _
        StringFormat("%.2f GB", DriveSpaceFree($arDrives[$i])), $MenuDrives)
Next

; WM_MEASUREITEM and WM_DRAWITEM are registered in 
; "ModernMenu.au3" so they don"t need to registered here
; Also OnAutoItExit() is in "ModernMenu.au3" to cleanup the
; menu imagelist and font

Dim $nTrayIcon2 = 0

; Create an icon which demonstrates how to use click event - see the function 'MyTrayTipCallBack'
Dim $nTrayIcon3 = _TrayIconCreate("Click me", "shell32.dll", 15, "MyTrayTipCallBack")

; Main GUI Loop

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $GUI_EVENT_CLOSE, $TrayExit
            ExitLoop
        Case $traycmd
            Run("CMD")
        Case $trayregedit
            Run("regedit.exe")
        Case $trayrun
            $trayrunbox = InputBox("Run", "Run:")
            Run($trayrunbox)
            
        Case $TrayAdvanced, $TraySimple
            If BitAnd(GUICtrlRead($TraySimple), $GUI_CHECKED) Then
                GUICtrlSetState($TraySimple, $GUI_UNCHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_CHECKED)
                $bUseAdvTrayMenu = TRUE
            Else
                GUICtrlSetState($TraySimple, $GUI_CHECKED)
                GUICtrlSetState($TrayAdvanced, $GUI_UNCHECKED)
                $bUseAdvTrayMenu = FALSE
            EndIf
            
        Case $TrayHelp
            If $nTrayIcon2 = 0 Then
                $nTrayIcon2 = _TrayIconCreate("New message", "shell32.dll", 13, "MyTrayTipCallBack")
            Else
                _TrayIconSetState($nTrayIcon2, 1)
            EndIf
            
            _TrayTip($nTrayIcon2, "New message", "A new message has arrived." & @CRLF & "Please click here to read...", 15, $NIIF_INFO)                         
        Case $trayrun
            $runit = InputBox("Run", "Run:")
            Run($runit)
    EndSwitch
WEnd

_TrayIconDelete($nTrayIcon1)
_TrayIconDelete($nTrayIcon3)

If $nTrayIcon2 > 0 Then _TrayIconDelete($nTrayIcon2)

Exit


Func MyTrayTipCallBack($nID, $nMsg)
    Switch $nID
        Case $nTrayIcon2
            Switch $nMsg
                Case $NIN_BALLOONUSERCLICK, $NIN_BALLOONTIMEOUT
                    If $nMsg = $NIN_BALLOONUSERCLICK Then MsgBox(64, "Help!", "This Is A Simple Sample"&@CRLF&"Of Color Edit")
                    _TrayIconSetState($nTrayIcon2, 2)
            EndSwitch
            
        Case $nTrayIcon3
            Switch $nMsg
;;; Case $WM_LBUTTONDOWN
    ; Put your stuff here
;;; case $WM_LBUTTONUP
    ; Put your stuff here; One click and double click to put together is difficult
                case $WM_LBUTTONDBLCLK
                    MsgBox(0, "Info", "You left double clicked on TrayIcon3.")
                    GUISetState(@SW_RESTORE, $hMainGUI); Restore/put focus back to our main GUI
;;; case $WM_RBUTTONDOWN
    ; Put your stuff here
                case $WM_RBUTTONUP
                    MsgBox(0, "Info", "You right clicked on TrayIcon3.")
        ; Restore/put focus back to our main GUI
;;; case $WM_RBUTTONDBLCLK
    ; Put your stuff here
;;; case $WM_MOUSEMOVE
    ; Put your stuff here
            EndSwitch
    EndSwitch
EndFunc
Can't see why my suggestion is no good.

In your post you had

Case $trayrun
            $runit = InputBox("Run", "Run:")
            If $GUI_EVENT_CLOSE Then Exit
            Else
            Run($runit)

The code in my reply was

$runit = InputBox("Run", "Run:")
Switch @error
   Case 1;Cancel or Close clicked
            ;do something
   Case 0
        if FileExists($runit) then Run($runit)
EndSwitch

which was to replace your faulty code after the "Case $trayrun".

If you want it to exit then where I put a comment "do something" just add the line "exit" (without the quotation marks of course).

If I am not understanding what you want then you will need to spell it out to me.

EDIT: spelling.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...