Jump to content

[Solved] Tray Menu


Recommended Posts

When I click yes it displays the correct message box but when I click no it displays the yes message box instead of the no message box.

How can I get the no to display the correct message box?

#include <IE.au3>
#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
HotKeySet("{ESC}", "_Exit")

Global $itmYes, $itmNo, $citmY, $citmN

$Test1 = TrayCreateMenu("Test1")
$itmYes = TrayCreateItem("Yes", $Test1)
$itmNo  = TrayCreateItem("No", $Test1)
TrayCreateItem("")
$itmExit        = TrayCreateItem("Exit")
TraySetState()


While 1
    
    $tMsg = TrayGetMsg()
    Switch $tMsg
        Case 0
            ContinueLoop
        
        Case $itmYes, $itmNo                
            _TrayCheck1()
            
        Case $itmExit
            _Exit()
    EndSwitch
WEnd

Func _TrayCheck1()  
    $citmY = TrayItemGetText($itmYes)
    $citmN = TrayItemGetText($itmNo)
    If $citmY = "Yes" Then
        MsgBox(0, "Debug:", "$citmY: Create Desktop Shortcut = " & $citmY)
    ElseIf $citmN = "No" Then
        MsgBox(0, "Debug:", "$citmN: Create Desktop Shortcut = " & $citmN)
    EndIf
EndFunc     ;==>_TrayCheck1

Func _Exit()
    GUIDelete()
    Exit
EndFunc     ;_Exit

Thank you for your help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

#include <IE.au3>
#include <Constants.au3>

#NoTrayIcon

Opt("TrayMenuMode", 1)

HotKeySet("{ESC}", "_Exit")

Global $citmY, $citmN

Global $Test1 = TrayCreateMenu("Test1")
Global $itmYes = TrayCreateItem("Yes", $Test1)
Global $itmNo = TrayCreateItem("No", $Test1)
TrayCreateItem("")
Global $itmExit = TrayCreateItem("Exit")
TraySetState()

Global $tMsg

While 1

    $tMsg = TrayGetMsg()

    Switch $tMsg

        Case $itmYes, $itmNo

            _TrayCheck1($tMsg)

        Case $itmExit

            _Exit()
    EndSwitch
WEnd

Func _Exit()
    GUIDelete()
    Exit
EndFunc ;==>_Exit

Func _TrayCheck1(Const $item)

    Switch TrayItemGetText($item)

        Case "Yes"

            $citmY = "Yes"
            
            MsgBox(0, "Debug:", "$citmY: Create Desktop Shortcut = " & $citmY)

        Case "No"

            $citmN = "No"
            
            MsgBox(0, "Debug:", "$citmN: Create Desktop Shortcut = " & $citmN)
    EndSwitch
EndFunc ;==>_TrayCheck1

Edited by jaberwocky6669
Link to comment
Share on other sites

Your first "if" comparison is always true and thus the "else" gets ignored all the time.

Quick and dirty fix is to pass the tMsg to the function:

#include <IE.au3>
#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
HotKeySet("{ESC}", "_Exit")

Global $itmYes, $itmNo, $citmY, $citmN

$Test1 = TrayCreateMenu("Test1")
$itmYes = TrayCreateItem("Yes", $Test1)
$itmNo  = TrayCreateItem("No", $Test1)
TrayCreateItem("")
$itmExit        = TrayCreateItem("Exit")
TraySetState()


While 1
    
    $tMsg = TrayGetMsg()
    Switch $tMsg
        Case 0
            ContinueLoop
        
        Case $itmYes, $itmNo                
            _TrayCheck1($tMsg)
            
        Case $itmExit
            _Exit()
    EndSwitch
WEnd

Func _TrayCheck1($tMsg)  
    If $tMsg = $itmYes Then
        MsgBox(0, "Debug:", "$citmY: Create Desktop Shortcut = Yes")
    ElseIf $tMsg = $itmNo  Then
        MsgBox(0, "Debug:", "$citmN: Create Desktop Shortcut = No")
    EndIf
EndFunc     ;==>_TrayCheck1

Func _Exit()
    GUIDelete()
    Exit
EndFunc     ;_Exit

However, I would prefer to make use of the already existing Switch-Case:

#include <IE.au3>
#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
HotKeySet("{ESC}", "_Exit")

Global $itmYes, $itmNo, $citmY, $citmN

$Test1 = TrayCreateMenu("Test1")
$itmYes = TrayCreateItem("Yes", $Test1)
$itmNo  = TrayCreateItem("No", $Test1)
TrayCreateItem("")
$itmExit = TrayCreateItem("Exit")
TraySetState()


While 1
    $tMsg = TrayGetMsg()
    Switch $tMsg
        Case 0
            ContinueLoop
        
        Case $itmYes                
            _TrayCheck1Yes()
        
        Case $itmNo
            _TrayCheck1No()
            
        Case $itmExit
            _Exit()
    EndSwitch
WEnd

Func _TrayCheck1Yes()
    MsgBox(0, "Debug:", "Create Desktop Shortcut = Yes")
EndFunc

Func _TrayCheck1No()
    MsgBox(0, "Debug:", "Create Desktop Shortcut = No")
EndFunc

Func _Exit()
    GUIDelete()
    Exit
EndFunc

Or another way to do it:

#include <IE.au3>
#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
HotKeySet("{ESC}", "_Exit")

Global $itmYes, $itmNo, $citmY, $citmN

$Test1 = TrayCreateMenu("Test1")
$itmYes = TrayCreateItem("Yes", $Test1)
$itmNo  = TrayCreateItem("No", $Test1)
TrayCreateItem("")
$itmExit = TrayCreateItem("Exit")
TraySetState()


While 1
    $tMsg = TrayGetMsg()
    Switch $tMsg
        Case 0
            ContinueLoop
        
        Case $itmYes                
            _TrayCheck1("Yes")
        
        Case $itmNo
            _TrayCheck1("No")
            
        Case $itmExit
            _Exit()
    EndSwitch
WEnd

Func _TrayCheck1($param)
    MsgBox(0, "Debug:", "Create Desktop Shortcut = " & $param)
EndFunc

Func _Exit()
    GUIDelete()
    Exit
EndFunc
Link to comment
Share on other sites

Quick and dirty fix is to pass the tMsg to the function:

How is my example quick and dirty so that I may accept reproof.

Edited by jaberwocky6669
Link to comment
Share on other sites

jaberwocky6669 and Torx thank you for your help. The examples each of you provided were excatly what I was looking for and solved my problem.

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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...