Jump to content

Need some help please.


 Share

Recommended Posts

Hello there i am new to autoit and i am having some problems with getting my traymenu to uncheck and stop the action. Then when checked again start back up and be checked. i have searched again the forums and found a problem almost the same but. I i dont want 2 items on the menu like... one for turning on and one for turning off all i want is ( Check turn on. Uncheck turn off.) Here is my code thank you.

#include <Inet.au3>
#Include <Constants.au3>
#NoTrayIcon
HotKeySet("{esc}","Exitme")

$PublicIP = _GetIP()
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$prefsitem  = TrayCreateMenu("Preferences")
$showpublicIP = TrayCreateItem("Show Public IP",$prefsitem)
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exititem   = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $prefsitem
            
        Case $msg = $aboutitem  
            Msgbox(64, "about:", "HandyTool Version:1.0")

        Case $msg = $ShowPublicIP
            TrayItemSetState($ShowPublicIP,$TRAY_CHECKED)
            SplashTextOn("","Public IP is: "& $PublicIP,200,12,1060,0,1,"Lucida Console",9)
            Uncheckingshowip()

        Case $msg = $exititem
            exit 0
            ExitLoop
    EndSelect
WEnd

Exit

Func Uncheckingshowip()
    If BitAND(TrayItemGetState($ShowPublicIP), $TRAY_CHECKED)Then 
         BitAND(TrayItemGetState($ShowPublicIP), $TRAY_UNCHECKED)
        
     ;ElseIf
          ;BitAND(TrayItemGetState($ShowPublicIP), $TRAY_CHECKED) = $TRAY_UNCHECKED Then
          ;BitAND(TrayItemGetState($ShowPublicIP), $TRAY_UNCHECKED
        ; SplashOff()
    EndIf
EndFunc


Func Exitme()
    exit 0
    EndFunc
Link to comment
Share on other sites

Try this:

#include <Inet.au3>
#Include <Constants.au3>
#NoTrayIcon
HotKeySet("{esc}", "Exitme")

$PublicIP = _GetIP()
Opt("TrayMenuMode", 3)   ;CHANGED

$prefsitem = TrayCreateMenu("Preferences")
$showpublicip = TrayCreateItem("Show Public IP", $prefsitem)
$aboutitem = TrayCreateItem("About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $prefsitem

        Case $msg = $aboutitem
            MsgBox(64, "about:", "HandyTool Version:1.0")

        Case $msg = $showpublicip
            If TrayItemGetState($showpublicip) = $TRAY_UNCHECKED + $TRAY_ENABLE Then  ;ADDED/CHANGED the next few lines
                TrayItemSetState($showpublicip, $TRAY_CHECKED)
                SplashTextOn("", "Public IP is: " & $PublicIP, 200, 12, 1060, 0, 1, "Lucida Console", 9)
            Else
                TrayItemSetState($showpublicip, $TRAY_UNCHECKED)
                SplashOff()
            EndIf
        Case $msg = $exititem
            Exit 0
            ExitLoop
    EndSelect
WEnd

Exit

;REMOVE - this function isn't necessary... or you could put the if/else/endif in it from the while/wend i suppose
Func Uncheckingshowip()
    If BitAND(TrayItemGetState($showpublicip), $TRAY_CHECKED) Then
        BitAND(TrayItemGetState($showpublicip), $TRAY_UNCHECKED)

        ;ElseIf
        ;BitAND(TrayItemGetState($ShowPublicIP), $TRAY_CHECKED) = $TRAY_UNCHECKED Then
        ;BitAND(TrayItemGetState($ShowPublicIP), $TRAY_UNCHECKED
        ; SplashOff()
    EndIf
EndFunc


Func Exitme()
    Exit 0
EndFunc

edit - added a couple notes

Edited by xcal
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...