Spacetech Posted February 22, 2008 Share Posted February 22, 2008 I'm trying to create a program that when i double click the tray icon it will toggle a screen to show / hide. Also when you right click it i want it to bring up the about and exit tray icon selections. I can't seem to get it to work. Heres my script expandcollapse popup#include <Constants.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) $Window = "Notepad" TraySetIcon("shell32.dll", 21) TraySetToolTip($Window & " Hider") $About = TrayCreateItem("About") $Exit = TrayCreateItem("Exit") TraySetState() $Hidden = false TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "HiddenToggle") While 1 $Tray = TrayGetMsg() Select Case $Tray = $About Msgbox(64, "About...", "|---|") Case $Tray = $Exit ExitLoop EndSelect WEnd Func HiddenToggle() Select Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOUBLE If($Hidden == false) Then WinSetState($Window, "", @SW_HIDE) $Hidden = true Else WinSetState($Window, "", @SW_SHOW) EndIf EndSelect EndFunc Func OnAutoItExit() If($Hidden == true) Then WinSetState($Window, "", @SW_SHOW) EndIf EndFunc Exit Link to comment Share on other sites More sharing options...
smashly Posted February 22, 2008 Share Posted February 22, 2008 (edited) Hi, part of your problem is you can't use TrayGetMsg() and TrayOnEventMode 1 at the same time.. It's either one or the other not both.expandcollapse popup#include <Constants.au3> Opt("WinTitleMatchMode", 2) ; Enable partial window title match Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Global $Window = " - Notepad", $Hidden TraySetClick(16) ; Set the tray click for menu to secondary mouse up TraySetIcon("shell32.dll", 21) TraySetToolTip($Window & " Hider") $About = TrayCreateItem("About") TrayItemSetOnEvent(-1, "TrayEvent") TrayCreateItem("") $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "TrayEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent") TraySetState() While 1 Sleep(100) WEnd Func TrayEvent() Switch @TRAY_ID Case $TRAY_EVENT_PRIMARYDOUBLE If Not $Hidden And WinExists(" - Notepad") Then WinSetState($Window, "", @SW_HIDE) $Hidden = 1 ElseIf $Hidden And WinExists(" - Notepad") Then WinSetState($Window, "", @SW_SHOW) $Hidden = 0 EndIf Case $About Msgbox(64, "About...", "|---|") Case $Exit If $Hidden And WinExists(" - Notepad") Then WinSetState($Window, "", @SW_SHOW) Exit EndSwitch EndFunc Cheers Edited February 22, 2008 by smashly Link to comment Share on other sites More sharing options...
Achilles Posted February 22, 2008 Share Posted February 22, 2008 expandcollapse popup#include <Constants.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) TraySetClick(8); <-- makes it so you have to right click the tray (not necessary but more professional in my view) $Window = "Untitled - Notepad" TraySetIcon("shell32.dll", 21) TraySetToolTip($Window & " Hider") $About = TrayCreateItem("About") TrayItemsetOnEVent(-1, '_About'); <--- TrayItemSetOnEvent is needed in TrayOnEventMode, you can't use TrayGetMsg() $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, '_Exit') TraySetState() $Hidden = false TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "HiddenToggle") While 1 Sleep(200) WEnd Func HiddenToggle() If Not $hidden Then WinSetState($Window, "", @SW_HIDE) Else WinSetState($Window, "", @SW_SHOW) EndIf $Hidden = Not $hidden; $hidden equals whatever it isn't EndFunc Func _About() Msgbox(64, "About...", "|---|") EndFunc Func _Exit() Exit EndFunc Func OnAutoItExit() If($Hidden == true) Then WinSetState($Window, "", @SW_SHOW) EndIf EndFunc My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Spacetech Posted February 22, 2008 Author Share Posted February 22, 2008 Thanks it works great now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now