Jump to content

Tray Icon


Recommended Posts

I've got this script from the Helpfiles, and I've modified it a little bit:

#Include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode",1)
$display = TrayCreateItem("Display")
TrayCreateItem("")
$exit = TrayCreateItem("Exit")
TraySetState()
While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $display
        GUISetState(@SW_SHOW)
        Case $msg = $exit
            ExitLoop
    EndSelect
WEnd

Exit

When I ran that script, everything was fine, the tray icon was there, so did the menu. But, when I've added it to my script, this customized menu wasn't there, but, instead, it was the normal Pause Script/Exit menu. I've put the above code both to the end and to the beggining of my script... no luck. What can I do about it? And, why it's #NoTrayItem in the helpfile, if we actually want a customized tray?

And the last thing I want is, when i minimize the script, it shouldn't appear on the taskbar, and it should be displayed again with the above code. Is this possible? Thanks!

Edit: Ok, now I understood that for the Display button to work properly, the function would have to be something like _WinMaximize, and not GUISetState(@SW_SHOW). Does anybody know what's the function called?

Edit2: Hmm... Maybe, the top right "x" should make the GUI "rest" on the tray, using Case $GUI_EVENT_CLOSE, but how?:)

Edited by Kiti
Link to comment
Share on other sites

I would use the tray as the main of your script. then put the script with your GUI in a function and call it when the display in the tray it being hit.

Regards

Brilliant!!! Thank you!

And now, how can I close the function?:) I've tried "Exit _function()" but each time I exit another instance of the GUI appears. Sorry for the newbie questions :P

Edit: I've tried WinKill but no luck...

Edit2: Hmm... Maybe it can be done using GuiSetState(@SW_HIDE) and GUISetState(@SW_SHOW). Let me think a little bit.... :P

Edited by Kiti
Link to comment
Share on other sites

#include <ExcelCOM_UDF.au3>
#include <GUIConstantsEx.au3>


Local $oExcel = _ExcelBookNew(1)
For $K = 1 To 25
    _ExcelWriteCell($oExcel, "Step 1", $K, 1)
Next

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$display = TrayCreateItem("Display")
TrayCreateItem("")
$exit = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $display
        _show()
        Case $msg = $exit
            ExitLoop
    EndSelect
WEnd



Func _show()
Local $YesID, $ExitID, $msg
$gui = GUICreate("Custom Msgbox", 210, 80)
GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Validate!", 25, 40, 100, 30)
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)

GUISetState(@SW_SHOW); display the GUI

$Note_win = WinGetHandle("Custom Msgbox", "")
WinMove($Note_win, "", 700, 10)
WinSetOnTop("Custom Msgbox", "", 1)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $YesID
            WinActivate("[CLASS:XLMAIN]", "")
            Send("{DOWN}"); fixes a bug: if you write "x" on a cell, and you don't select another cell, the GUI exits.
            $Cell = _ExcelFindInRange($oExcel, 'x', 1, 2, 25, 2, 0, 2, False, False)
            For $i = 1 To $Cell[0][0]
                $Step = _ExcelReadCell($oExcel, $Cell[$i][3], $Cell[$i][2] - 1)
                $level = StringTrimLeft($Step, 5)
                $nextlevel = $level + 1
                _ExcelWriteCell($oExcel, "Step " & $nextlevel, $Cell[$i][3], $Cell[$i][2] - 1)
            Next
            _ExcelReplaceInRange($oExcel, "x", "", 1, 2, 25, 2, 2, False, "", False)
        Case $ExitID
            GuISetState(@SW_Hide)
        Case $GUI_EVENT_CLOSE
           GuISetState(@SW_Hide)
    EndSwitch
    WEnd
    Endfunc
    
    Exit

Why it's not working? What's wrong? I can show, and then hide, but just once.

Please someone help me! :)

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