Sign in to follow this  
Followers 0
maestro1024

Tray create item in background

6 posts in this topic

I have a function that creates a some custom menus in the tray using trayCreateItem and the msg loop like the example.

Problem is the loop does not move on until I press exit menu in the tray. I really want to just create the menus and then if the user selects one of the menus then do something. Is this possible? Can I do it this with the loop?

Thanksu

Modeled after the help file.

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $prefsitem

Msgbox(64, "Preferences:", "OS:" & @OSVersion)

Case $msg = $aboutitem

Msgbox(64, "about:", "AutoIt3-Tray-sample.")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Share this post


Link to post
Share on other sites



I have a function that creates a some custom menus in the tray using trayCreateItem and the msg loop like the example.

Problem is the loop does not move on until I press exit menu in the tray. I really want to just create the menus and then if the user selects one of the menus then do something. Is this possible? Can I do it this with the loop?

Thanksu

Modeled after the help file.

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $prefsitem

Msgbox(64, "Preferences:", "OS:" & @OSVersion)

Case $msg = $aboutitem

Msgbox(64, "about:", "AutoIt3-Tray-sample.")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

The help file's method works perfectly, allows you to select and then run whatever you want. Just make sure you model it properly.

#Include <Constants.au3>
#NoTrayIcon

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

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Display", $settingsitem)
$printeritem    = TrayCreateItem("Printer", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $displayitem
            msgbox(0, "Test", "Display item checked")
        Case $msg = $printeritem
            msgbox(0, "Test", "Printer item checked")
        Case $msg = $aboutitem
            Msgbox(64,"About:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
Exit

Either that, or we just don't understand your question :D


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

Maybe I wasn't clear. I want to setup the menus and have them available but I don't want the user to have to use them at all if they don't want.

I added a msgbox after the example in the helpful. What I see is it never gets to the msgbox unless I select exit from the taksbar to get out of the loop. Is there a way to set the msgbox functions so that they will be there but don't have to be used at all?

CODE

#Include <Constants.au3>

#NoTrayIcon

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

$prefsitem = TrayCreateItem("Preferences")

TrayCreateItem("")

$aboutitem = TrayCreateItem("About")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $prefsitem

Msgbox(64, "Preferences:", "OS:" & @OSVersion)

Case $msg = $aboutitem

Msgbox(64, "about:", "AutoIt3-Tray-sample.")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

;Exit

MsgBox(0,"","Did I get here?")

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Maybe I wasn't clear. I want to setup the menus and have them available but I don't want the user to have to use them at all if they don't want.

I added a msgbox after the example in the helpful. What I see is it never gets to the msgbox unless I select exit from the taksbar to get out of the loop. Is there a way to set the msgbox functions so that they will be there but don't have to be used at all?

CODE

#Include <Constants.au3>

#NoTrayIcon

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

$prefsitem = TrayCreateItem("Preferences")

TrayCreateItem("")

$aboutitem = TrayCreateItem("About")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $prefsitem

Msgbox(64, "Preferences:", "OS:" & @OSVersion)

Case $msg = $aboutitem

Msgbox(64, "about:", "AutoIt3-Tray-sample.")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

;Exit

MsgBox(0,"","Did I get here?")

In th is situation you would use the 'Switch' command instead of select:

#Include <Constants.au3>
#include <GuiConstants.au3>
#NoTrayIcon

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


$form = GUICreate("Test", 400, 400)
$prefsitem = TrayCreateItem("Preferences")
TrayCreateItem("")
$aboutitem = TrayCreateItem("About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

$test = GUICtrlCreateInput("", 0, 0, 300, 20)
$button = GUICtrlCreateButton("Submit", 310, 0, 90, 25)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    $nmsg = TrayGetMsg()
    switch $nmsg
            Case $prefsitem
                Msgbox(64, "Preferences:", "OS:" & @OSVersion)
            Case $aboutitem
                Msgbox(64, "About:", "AutoIt3-Tray-sample.")
            Case $exititem
                ExitLoop
    EndSwitch
    switch $msg
        Case $GUI_EVENT_CLOSE
             Exit
        case $button
            MsgBox(0, "Info", GuiCtrlRead($test), 1)
    EndSwitch
WEnd

Sorry it took so long to answer you :D As you'll note in the script, the main loop of the script looks for both GUI messages and TRAY messages, and then switches each variable in turn. So, each, of course has their own name, such as $msg and $nMSG.

To use your example above, where you wanted a MSG box to display AFTER setting the message information, you simply wouldn't do that. If you wanted the script to say 'Hey, i'm running, use the tray menu for options', then you would put that MSGBOX FIRST and then define the rest of your script.

However, I have a feeling you were more asking how it would be possible to have the TRAY MENU and GUI menu as well :D

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

I am trying to do other processing not necessarily a GUI.

I think you have answered my question.

What I wanted to do was to setup these menus and move on to my other processing. The way you can setup an Adlib or a hotkey. But I think what you are saying is that is not how they work in Autoit. I would have to add whatever other processing I want to the message queue.

Let me know if that is not correct

Thanks again for looking at it.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am trying to do other processing not necessarily a GUI.

I think you have answered my question.

What I wanted to do was to setup these menus and move on to my other processing. The way you can setup an Adlib or a hotkey. But I think what you are saying is that is not how they work in Autoit. I would have to add whatever other processing I want to the message queue.

Let me know if that is not correct

Thanks again for looking at it.

it is possible:

#Include <Constants.au3>
#include <GuiConstants.au3>
#NoTrayIcon

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


$prefsitem = TrayCreateItem("Preferences")
TrayCreateItem("")
$aboutitem = TrayCreateItem("About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
    $nmsg = TrayGetMsg()
    switch $nmsg
            Case $prefsitem
                Msgbox(64, "Preferences:", "OS:" & @OSVersion)
            Case $aboutitem
                Msgbox(64, "About:", "AutoIt3-Tray-sample.")
            Case $exititem
                ExitLoop
            Case Else
                   call("OTHERFUNCTIONS")
    EndSwitch
WEnd

Keep in mind that will repeatedly call the OTHERFUNCTIONS; it's difficult to fully help you without seeing your ENTIRE script or the ENTIRE process that you want to complete. There isn't much that AUTOIT cannot do, so don't give up. Just give us a full idea of what you want.

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
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
Sign in to follow this  
Followers 0