Tray

Tray icon controller

Using this module you can totally control Windows notification area.  Your script can create any number of tray icons and receive notifications about user actions on them.  Also, you can get and modify 3thd party tray icons information.

Summary
TrayTray icon controller
AddAdd icon in the system tray.
ClickClick the tray icon.
CountGet the number of icons in the notificaiton area.
DefineGet information about system tray icons.
DisableDisable the notification area.
FocusFocus notification icon or window.
GetRectGet tray icon rect.
GetTooltipGet tooltip of the tray icon.
ModifyModify icon properties.
MoveMove the tray icons.
RemoveRemoves the tray icon.
RefreshRefresh tray icons.
Example
About

Add

Tray_Add(hGui,  
Handler,  
Icon,  
Tooltip = "")

Add icon in the system tray.

Parameters

hGuiHandle of the parent window.
HandlerNotification handler.
IconIcon path or handle.  Icons allocated by module will be automatically destroyed when Remove function returns.  If you pass icon handle, Remove will not destroy it.  If path is an icon resource, you can use “path:idx” notation to get the handle of the desired icon by its resource index (0 based).
TooltipTooltip text.

Notifications

Handler(Hwnd, Event)
HwndHandle of the tray icon.
EventL (Left click), R(Right click), M (Middle click), P (Position - mouse move).  Additionally, “u” or “d” can follow event name meaning “up” and “doubleclick”.  For example, you will be notified on “Lu” when user releases the left mouse button.

Returns

0 on failure, handle on success.

Click

Tray_Click(Position,  
Button = "L")

Click the tray icon.

Parameters

PositionPosition of the tray icon.
Button”L”, “R”, “M” or “Ld”.

Count

Tray_Count()

Get the number of icons in the notificaiton area.

Define

Tray_Define( Filter = "",
 pQ = "",
ByRef o1 = "~`a ",
ByRef o2 = "",
ByRef o3 = "",
ByRef o4 = "",
ByRef o5 = "",
ByRef o6 = "",
ByRef o7 = "")

Get information about system tray icons.

Parameters

FilterContains process name, ahk_pid, ahk_id or 1-based position for which to return information.  If you specify position as Filter, you can use output variables to store information.
pQQuery parameter, by default “ihw”.
o1..o4Reference to output variables.

Query

hHandle.
iPosItion (1 based).
wParent Window handle.
pProcess Pid.
nProcess Name.
mMessage id.
oIcOn handle.

Returns

String containing icon information per line.

Disable

Tray_Disable(bDisable = true)

Disable the notification area.

Remarks

The shell must be restarted for the changes to take effect.  See <Shell_Restart> for details.

Focus

Tray_Focus(hGui = "",
hTray = "")

Focus notification icon or window.

Parameters

hGuiHandle of the parent window.
hTrayTray icon handle.  This icon will be focused.  As a consequence, you can use SPACEBAR or ENTER instead left click and windows popup keyboard button as rclick.  Arrows can be used to select other icons.  However, there is no visual representation of selection apart from the tooltip that is shown after few moments.

Remarks

If both parameters are missing, function will focus Notification area.

GetRect

Tray_GetRect( Position,  
ByRef x = "",
ByRef y = "",
ByRef w = "",
ByRef h = "")

Get tray icon rect.

Parameters

PositionPosition of the tray icon.  Use negative position to retreive client coordinates.
x-hRefrence to outuptu variables, optional.

Returns

String containing all outuput variables.

Remarks

This function can be used to determine if tray icon is hidden.  Such tray icons will have string “0 0 0 0” returned.

GetTooltip

Tray_GetTooltip(Position)

Get tooltip of the tray icon.

Parameters

PositionPosition of the tray icon.

Modify

Tray_Modify(hGui,  
hTray,  
Icon,  
Tooltip = "~`a ")

Modify icon properties.

Parameters

hGuiHandle of the parent window.
hTrayHandle of the tray icon.
IconIcon path or handle, set to “” to skip.
TooltipToolTip text, omit to keep the current tooltip.

Returns

TRUE on success, FALSE otherwise.

Move

Tray_Move(Pos,  
NewPos = "")

Move the tray icons.

Parameters

PosPosition of the icon to move, 1 based.
NewPosNew position of the icon, if omited, icon will be moved to the end.

Returns

TRUE on success, FALSE otherwise.

Remove

Tray_Remove(hGui,  
hTray = "")

Removes the tray icon.

Parameters

hGuiHandle of the parent window.
hTrayHandle of the tray icon.  If omited, all icons owned by the hGui will be removed.

Returns

TRUE on success, FALSE otherwise.

Refresh

Tray_Refresh()

Refresh tray icons.

Remarks

If process exits forcefully, its tray icons wont be removed.  Call this function to refresh the notification area in such cases.

Example

    Gui,  +LastFound
    hGui := WinExist()

    Tray_Add( hGui, "OnTrayIcon", "shell32.dll:1", "My Tray Icon")
return

OnTrayIcon(Hwnd, Event){
    if (Event != "R")       ;return if event is not right click
        return

    MsgBox Right Button clicked
}
Tray_Add(hGui,  
Handler,  
Icon,  
Tooltip = "")
Add icon in the system tray.
Tray_Click(Position,  
Button = "L")
Click the tray icon.
Tray_Count()
Get the number of icons in the notificaiton area.
Tray_Define( Filter = "",
 pQ = "",
ByRef o1 = "~`a ",
ByRef o2 = "",
ByRef o3 = "",
ByRef o4 = "",
ByRef o5 = "",
ByRef o6 = "",
ByRef o7 = "")
Get information about system tray icons.
Tray_Disable(bDisable = true)
Disable the notification area.
Tray_Focus(hGui = "",
hTray = "")
Focus notification icon or window.
Tray_GetRect( Position,  
ByRef x = "",
ByRef y = "",
ByRef w = "",
ByRef h = "")
Get tray icon rect.
Tray_GetTooltip(Position)
Get tooltip of the tray icon.
Tray_Modify(hGui,  
hTray,  
Icon,  
Tooltip = "~`a ")
Modify icon properties.
Tray_Move(Pos,  
NewPos = "")
Move the tray icons.
Tray_Remove(hGui,  
hTray = "")
Removes the tray icon.
Tray_Refresh()
Refresh tray icons.
Close