Jump to content

Traymenu help, with switch


Recommended Posts

Hi all!

I have a problem with creating the right varibles in the switch statment and wonder if some on can help me figure out the best way to procide?

i got the part when i create all trayitems with a "FOR" statement from an ini file working, but i fail when it comes to the switch statement.

ini file look like this..

[Links]

Calulator=Calc.exe

and so on...

 

here is part of my script..

it works for a few min.. then the hole application hangs (when compiled, seems to work in test mode, before i compile it?)

is this part that seems to cose the error?

Case Else
                    If $Msg > 0 Then
                    _DebugOut("While Statement - $Msg: " & $Msg)
                    $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0)
                    If @error Then

                    Else
                    $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0)
                    If @error Then

                    Else
                    _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0])
                    _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1])
                    ShellExecute($Linksarray[$aSearch][1], "", "", "open")
                    EndIf
                    EndIf
                    EndIf

here is both functions...

Func _WinMain()
    _readConfigFile()
    Opt("TrayMenuMode", 11)
    Opt("GUIOnEventMode", 0) ;0=disabled, 1=OnEvent mode enabled

    _TrayInit()
    ; Main GUI Loop
    Local $tvHandle = 0
    $iBegin = TimerInit()
    $LatencyUrl = IniRead($ConfigFile, "General", "LatencyUrl", "www.charger.se")
    $LatencyMS = IniRead($ConfigFile, "General", "LatencyMS", "500")
    HotKeySet("+!z", '_ShowITSupport')
    HotKeySet("+!x", '_ShowITSupport')



    While 1
        $Msg = GUIGetMsg()
        $gText = _GetMenuText($Msg)
        If TimerDiff($iBegin) > 5000 Then ; Loop until 5 sec have passed
            _Ping($LatencyUrl, $LatencyMS)
            #cs
                Local $net_test = _IsInternetConnectedEx()
                ;           ConsoleWrite("$net_test: " & $net_test & @CRLF)
                If $net_test = 1 Then
                Local $net_test2 = __GetConnectedAdapterIPMAC()
                If StringInStr($net_test2, "Wireless") Or StringInStr($net_test2, "Wired") Then
                EndIf
                Else
                ConsoleWrite("$net_test2? " & __GetConnectedAdapterIPMAC() & @CRLF)
                EndIf
            #ce
            ;           ConsoleWrite("Counter: " & $iBegin & @CRLF)
            $iBegin = TimerInit()
        EndIf

        Switch $Msg
            Case $ToggleLogonUser
                _DebugOut("While Statement - $ToggleLogonUser: " & $gText)
                _ToggleLogonUser()

            Case $TrayTS
                _DebugOut("While Statement - $TrayTS: " & $gText)
                _DebugOut(@ScriptDir & "TeamViewerQS_sv-idcnnz7xxq.exe" & @CRLF)
                FileInstall("Res\TeamViewerQS_sv-idcnnz7xxq.exe", @ScriptDir & "\TeamViewerQS_sv-idcnnz7xxq.exe", 0)
                ShellExecute("TeamViewerQS_sv-idcnnz7xxq.exe", "", @ScriptDir, 'open')
                ;           Sleep(10000)
            Case $ResetInternet
                _DebugOut("While Statement - $ResetInternet: " & $gText)
                $tmpNessage = MsgBox(20, "Warning", "You are about to do a complete Network reset!")
                If $tmpNessage = 6 Then
                    _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage)
                Else
                    _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage)
                EndIf

            Case $TrayExit
                _DebugOut("While Statement - $TrayExit: " & $gText)
                _TrayIconDelete($nTrayIcon1)
                ExitLoop
            Case Else
                #cs
                    If $Msg > 0 Then
                    _DebugOut("While Statement - $Msg: " & $Msg)
                    $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0)
                    If @error Then

                    Else
                    $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0)
                    If @error Then

                    Else
                    _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0])
                    _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1])
                    ShellExecute($Linksarray[$aSearch][1], "", "", "open")
                    EndIf
                    EndIf
                    EndIf
                #ce
        EndSwitch
        Sleep(10)
    WEnd
    _TrayIconDelete($nTrayIcon1)
EndFunc   ;==>_WinMain

Func _TrayInit()
    Opt('TrayMenuMode', 3) ; Default tray menu items (Script Paused/Exit) will not be shown.
    Opt('TrayAutoPause', 0) ; Script will not be paused when clicking the tray icon.
    ;Opt("TrayOnEventMode", 1)
    Opt('MustDeclareVars', 0)

    ; *** Create the tray icon ***
    ;Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0)

    ;TraySetIcon(@ScriptFullPath, "201")
    $nTrayIcon1 = _TrayIconCreate("Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2, @ScriptFullPath, -1)
    _TrayIconSetClick(-1, 16)
    _TrayIconSetState() ; Show the tray icon

    ; *** Create the tray context menu ***
    Local $iIndex = _ArraySearch($GeneralArray, "Kund", 0, 0, 0, 1, 1, 0)
    $TrayMenuname = "ChaQ - " & $GeneralArray[$iIndex][1]
    $nTrayMenu1 = _TrayCreateContextMenu() ; is the same like _TrayCreateContextMenu(-1) or _TrayCreateContextMenu($nTrayIcon1)
    $nSideItem3 = _CreateSideMenu($nTrayMenu1)
    _SetSideMenuText($nSideItem3, $TrayMenuname)
    _SetSideMenuColor($nSideItem3, 0x00FFFF) ; yellow; default color - white
    _SetSideMenuBkColor($nSideItem3, 0x802222) ; bottom start color - dark blue
    _SetSideMenuBkGradColor($nSideItem3, 0x4477AA) ; top end color - orange
    _SetSideMenuImage($nSideItem3, "shell32.dll", 309, True)

    $TrayCase = _TrayCreateItem("SupportCenter, Add a Case")
    _TrayCreateItem("")
    _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7)
    $TrayTS = _TrayCreateItem("Teamviwer")
    _TrayCreateItem("")
    _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9)
    $MenuLinks = _TrayCreateMenu("Links")
    _TrayCreateItem("")
    _TrayItemSetIcon($MenuLinks, "shell32.dll", -44)
    $MenuTools = _TrayCreateMenu("Program")
    _TrayCreateItem("")
    _TrayItemSetIcon($MenuTools, "", 0)
    $chargeitem = _TrayCreateMenu("Tools")
    $chargeitem1 = _TrayCreateMenu("Settings", $chargeitem)
    _TrayCreateItem("")

    $TrayExit = _TrayCreateItem("Exit")

    _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7)
    _TrayItemSetIcon($MenuLinks, "shell32.dll", -318)
    _TrayItemSetSelIcon($MenuLinks, "shell32.dll", -44)
    _TrayItemSetIcon($MenuTools, "shell32.dll", -20)
    _TrayItemSetSelIcon($MenuTools, "shell32.dll", -20)
    _TrayItemSetIcon($chargeitem, @ScriptFullPath, -11)
    _TrayItemSetSelIcon($chargeitem, @ScriptFullPath, -11)
    _TrayItemSetIcon($chargeitem1, @ScriptFullPath, -11)
    _TrayItemSetSelIcon($chargeitem1, @ScriptFullPath, -11)

    _TrayItemSetIcon($TrayHelp, "mstsc_101.ico", 0)
    _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9)
    _TrayItemSetIcon($TrayExit, "shell32.dll", -28)

    ; *** Sub menu items ***
    For $x = 1 To $Linksarray[0][0]
        _DebugOut("$Linksarray " & $Linksarray[$x][0])
        If StringInStr($Linksarray[$x][1], "http") Then
            $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuLinks)
            _TrayItemSetIcon($Tray_Item[$x], "shell32.dll", -14)
        Else
            $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuTools)
            _TrayItemSetIcon($Tray_Item[$x], $Linksarray[$x][1], "")
        EndIf

    Next

    $EnableBit = _TrayCreateItem("Enable (BIT/WSUS)", $chargeitem)
    $DisableBit = _TrayCreateItem("Disable (BIT/WSUS)", $chargeitem)
    $ResetInternet = _TrayCreateItem("Reset Internet Connection", $chargeitem)
    $ToggleLogonUser = _TrayCreateItem("Toggle Username/logon screen", $chargeitem)

    _TrayItemSetIcon($TrayTSSite, "shell32.dll", -14)
    _TrayItemSetIcon($TraySupportSite, "shell32.dll", -14)
    _TrayItemSetIcon($TraySupportSite1, "shell32.dll", -14)
    _TrayItemSetIcon($DisableBit, "shell32.dll", -275)
    _TrayItemSetIcon($EnableBit, "shell32.dll", -276)
    _TrayItemSetIcon($ResetInternet, @ScriptFullPath, -12)
    _TrayItemSetIcon($ToggleLogonUser, "regedit.exe", -1)



    GUICtrlSetState($chargeitem, $GUI_DISABLE)
    GUICtrlSetState($EnableBit, $GUI_DISABLE)
    GUICtrlSetState($DisableBit, $GUI_DISABLE)
    GUICtrlSetState($ResetInternet, $GUI_DISABLE)


EndFunc   ;==>_TrayInit

 

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

×
×
  • Create New...