Jump to content

Restore App from System Tray and Tray Tip Question


mdwerne
 Share

Recommended Posts

Hello,

On the following app can anyone tell how I might do two things?

1) Restore the app by clicking its system tray icon.

2) Refresh the tray tip every 10 seconds so it displays for a full minute and does not go away?

So far everything I've tried either breaks the app or starts crazy endless loops (aka breaks the app)

Here is my code:

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "_XMLDomWrapper.au3"
Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 1)
Global $sFile = (@ScriptDir & "\RTFMsg.xml")
Global $FormTitle, $RTFName, $ProgramName, $TrayTip, $ParamName, $AbortAllowed, $AbortButtonName, $ContinueButtonName, $i
_XMLFileOpen($sFile)
$FormTitle = _XMLGetAttrib("/MessageInfo/Title", "FormTitle")
$RTFName = _XMLGetAttrib("/MessageInfo/Display", "RTFName")
$ProgramName = _XMLGetAttrib("/MessageInfo/Program", "ProgramName")
$TrayTip = _XMLGetAttrib("/MessageInfo/TrayTip", "TrayTip")
$ParamName = _XMLGetAttrib("/MessageInfo/Param", "ParamName")
$AbortAllowed = _XMLGetAttrib("/MessageInfo/Abort", "AbortAllowed")
$AbortButtonName = _XMLGetAttrib("/MessageInfo/ABN", "AbortButtonName")
$ContinueButtonName = _XMLGetAttrib("/MessageInfo/CBN", "ContinueButtonName")
If WinExists($FormTitle) Then
WinActivate($FormTitle)
WinClose($FormTitle)
EndIf
_Main()
Func _Main()
Local $hGUI, $msg, $hRichEdit, $AbortButton, $ContinueButton
$hGUI = GUICreate($FormTitle, 900, 700, -1, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 880, 650, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$AbortButton = GUICtrlCreateButton($AbortButtonName, 700, 670, 50, 20)
$ContinueButton = GUICtrlCreateButton($ContinueButtonName, 828, 670, 60, 20)
GUISetState()
_GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\RichText.rtf")
_GUICtrlRichEdit_SetReadOnly($hRichEdit)
_GUICtrlRichEdit_GotoCharPos($hRichEdit, 0)
TrayTip("", $TrayTip, 10)
TraySetState(4)
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $ContinueButton
    Run(@ScriptDir & "\" & $ProgramName)
    Exit 0
   Case $msg = $GUI_EVENT_CLOSE Or $msg = $AbortButton
    Exit -1
  EndSelect
WEnd
EndFunc   ;==>_Main

Sample XML file:

<?xml version="1.0"?>
<MessageInfo>
  <Title FormTitle="Start Calculator"/>
<Display RTFName="RichText.rtf"/>
<Program ProgramName="Calc.exe"/>
<TrayTip TrayTip="You have an SCCM deployment!"/>
<Param ParamName=""/>
<Abort AbortAllowed="Y" />
<ABN AbortButtonName="Cancel"/>
<CBN ContinueButtonName="Continue"/>
</MessageInfo>

Thanks for any suggestions,

-Mike

Link to comment
Share on other sites

Ok...so I got the restore from tray "working"...any other suggestions would be welcomed. What's left is to keep the Tray Tip up for 60 seconds, any thoughts.

Code so far:

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "_XMLDomWrapper.au3"
#include <Constants.au3>
Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
Global $sFile = (@ScriptDir & "\RTFMsg.xml")
Global $FormTitle, $RTFName, $ProgramName, $TrayTip, $ParamName, $AbortAllowed, $AbortButtonName, $ContinueButtonName, $i, $opt, $trayMsg, $tlist_1, $tlist_2
_XMLFileOpen($sFile)
$FormTitle = _XMLGetAttrib("/MessageInfo/Title", "FormTitle")
$RTFName = _XMLGetAttrib("/MessageInfo/Display", "RTFName")
$ProgramName = _XMLGetAttrib("/MessageInfo/Program", "ProgramName")
$TrayTip = _XMLGetAttrib("/MessageInfo/TrayTip", "TrayTip")
$ParamName = _XMLGetAttrib("/MessageInfo/Param", "ParamName")
$AbortAllowed = _XMLGetAttrib("/MessageInfo/Abort", "AbortAllowed")
$AbortButtonName = _XMLGetAttrib("/MessageInfo/ABN", "AbortButtonName")
$ContinueButtonName = _XMLGetAttrib("/MessageInfo/CBN", "ContinueButtonName")
If WinExists($FormTitle) Then
WinActivate($FormTitle)
WinClose($FormTitle)
EndIf
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "RestoreFromTray")
_Main()
Func _Main()
Local $hGUI, $msg, $hRichEdit, $AbortButton, $ContinueButton
$hGUI = GUICreate($FormTitle, 900, 700, -1, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 880, 650, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$AbortButton = GUICtrlCreateButton($AbortButtonName, 700, 670, 50, 20)
$ContinueButton = GUICtrlCreateButton($ContinueButtonName, 828, 670, 60, 20)
GUISetState()
_GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\RichText.rtf")
_GUICtrlRichEdit_SetReadOnly($hRichEdit)
_GUICtrlRichEdit_GotoCharPos($hRichEdit, 0)
TrayTip("", $TrayTip, 10)
TraySetState(4)
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $ContinueButton
    Run(@ScriptDir & "\" & $ProgramName)
    Exit 0
   Case $msg = $GUI_EVENT_CLOSE Or $msg = $AbortButton
    Exit -1
  EndSelect
WEnd
EndFunc   ;==>_Main
; Functions
Func RestoreFromTray()
Select
  Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOWN
   GUISetState(@SW_RESTORE)
EndSelect
EndFunc   ;==>RestoreFromTray
Link to comment
Share on other sites

TrayTip ( "title", "text", timeout [, option] )

So... just change your timeout from 10 to 60

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

TrayTip ( "title", "text", timeout [, option] )

So... just change your timeout from 10 to 60

Hi kaotkbliss,

Thanks for the reply, I should have been more clear. I want the tray tip to keep refreshing after ten seconds even if the user clicks on the desktop, or tray icon, or popup bubble, or anywhere else. My hope is that if I do this for 60 seconds...that they will be motivated to start the deployment (by clicking the continue button).

So essentially I'm looking for the best place to put a loop (and how) that calls the Tray Tip function every ten seconds for 60 seconds. Hope that makes more sense.

Thanks again,

-Mike

Edited by mdwerne
Link to comment
Share on other sites

Ahh, put it in a func. then in your main loop use timerinit and timerdiff. When the specified amount of time has elapsed, call the func.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

One Last question. When I right click the System Tray Icon, the program does not always restore the GUI, double click always seems to work. I've read a few threads about setting the double click speed to determine what a single click is....but have no idea how to implement this.

Bottom-line, is there a way to consistently get my program to restore from the system tray with a single click?

Here is the code thus far.

#include "_XMLDomWrapper.au3"
#include <Constants.au3>
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Global $sFile = (@ScriptDir & "\Config.xml")
Global $hGUI, $FormTitle, $RTFName, $ProgramName, $TrayTip, $ShutdownTimer, $ParamName, $AbortAllowed, $AbortButtonName, $ContinueButtonName, $hRichEdit
_XMLFileOpen($sFile)
$FormTitle = _XMLGetAttrib("/MessageInfo/Title", "FormTitle")
$RTFName = _XMLGetAttrib("/MessageInfo/Display", "RTFName")
$ProgramName = _XMLGetAttrib("/MessageInfo/Program", "ProgramName")
$TrayTip = _XMLGetAttrib("/MessageInfo/TrayTip", "TrayTip")
$ShutdownTimer = _XMLGetAttrib("/MessageInfo/ShutdownTimer", "ShutdownTimer")
$ParamName = _XMLGetAttrib("/MessageInfo/Param", "ParamName")
$AbortAllowed = _XMLGetAttrib("/MessageInfo/Abort", "AbortAllowed")
$AbortButtonName = _XMLGetAttrib("/MessageInfo/ABN", "AbortButtonName")
$ContinueButtonName = _XMLGetAttrib("/MessageInfo/CBN", "ContinueButtonName")
If WinExists($FormTitle) Then
WinClose($FormTitle)
EndIf
If $ShutdownTimer = "" Then
$ShutdownTimer = 300000
EndIf
TrayTip("", $TrayTip, 5)
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "RestoreFromTray")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "RestoreFromTray")
TraySetState(4)
AdlibRegister("RefreshTrayTip", 10000)
AdlibRegister("ClickActiveWindow")
AdlibRegister("ShutdownTimer", $ShutdownTimer)
_Main()
; Functions
Func _Main()
Local $msg, $AbortButton, $ContinueButton
$hGUI = GUICreate($FormTitle, 900, 700, -1, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 880, 650, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$AbortButton = GUICtrlCreateButton($AbortButtonName, 700, 670, 50, 20)
$ContinueButton = GUICtrlCreateButton($ContinueButtonName, 828, 670, 60, 20)
GUISetState()
GUISetState(@SW_MINIMIZE)
_GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\RichText.rtf")
_GUICtrlRichEdit_SetReadOnly($hRichEdit)
_GUICtrlRichEdit_GotoCharPos($hRichEdit, 0)
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $ContinueButton
    Run(@ScriptDir & "\" & $ProgramName)
    _GUICtrlRichEdit_Destroy($hRichEdit) ;Not destorying the handle was causing the app to remian as a running process after the app quit.
    Exit 0
   Case $msg = $GUI_EVENT_CLOSE Or $msg = $AbortButton
    _GUICtrlRichEdit_Destroy($hRichEdit)
    Exit -1
  EndSelect
WEnd
EndFunc   ;==>_Main
Func RestoreFromTray()
Select
  Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOWN
   ;GUISetState(@SW_RESTORE)
   WinSetState($hGUI, "", @SW_SHOW)
   WinActivate($hGUI)
   ;MouseClick("Left", @DesktopWidth / 2, @DesktopHeight / 2, 1, 0)
   Send("{LCTRL} + {END}")
   ;Case @TRAY_ID = $TRAY_EVENT_PRIMARYDUBLE
   ; ;GUISetState(@SW_RESTORE)
   ; WinSetState($hGUI, "", @SW_SHOW)
   ; WinActivate($hGUI)
   ; ;MouseClick("Left", @DesktopWidth / 2, @DesktopHeight / 2, 1, 0)
   ; Send("{LCTRL} + {END}")
EndSelect
EndFunc   ;==>RestoreFromTray
Func RefreshTrayTip()
TrayTip("", $TrayTip, 5)
EndFunc   ;==>RefreshTrayTip
Func ClickActiveWindow()
If WinActive($FormTitle) Then
  MouseClick("Left", @DesktopWidth / 2, @DesktopHeight / 2, 1, 0)
  AdlibUnRegister("ClickActiveWindow") ;UnRegisterAdLib to kill the functionality
EndIf
EndFunc   ;==>ClickActiveWindow
Func ShutdownTimer()
_GUICtrlRichEdit_Destroy($hRichEdit)
Exit -1
EndFunc   ;==>ShutdownTimer

Thanks for any thoughts,

-Mike

Link to comment
Share on other sites

You say "on right click" but your code has

$TRAY_EVENT_PRIMARYDOWN

instead of

$TRAY_EVENT_SECONDARYDOWN

So I'm a little confused.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

You say "on right click" but your code has

$TRAY_EVENT_PRIMARYDOWN

instead of

$TRAY_EVENT_SECONDARYDOWN

So I'm a little confused.

Sorry...a duh moment on my part. Yes, I meant a left click. Ah the joys of dyslexia. :graduated:

I use an ergo mouse so in my case, it's the top button ;) . Regardless of positioning...I'm looking for the program to restore from the system tray after a single click of the Primary Mouse Button...I added the primarydouble mouse button in just for my testing...it is not required.

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