Class TPGTrayIcon95 (unit PGTray95)

Inherits from

TComponent

TPGTrayIcon95 - Windows 95/NT TrayIcon Component } { Note: "LoadCurrentIcon" and "NotifyShell" are the key methods here.

Constructors


constructor Create(AOwner: TComponent);

TPGTrayIcon95


Functions

procedure CloseForm(const AForm: TForm);

Closes a form and attempts to stop the Applications taskbar icon } { from showing.

destructor Destroy;

Replace the Applications's Minimize and Restore events with our own.

procedure DoSetForegroundWindow(Sender: TObject);


procedure HideApplication;

Restore the application if it isn't already restored.

procedure HideIcon;

Remove the icon from the system tray.

procedure LockScreenUpdates(ShouldLock: Boolean);


procedure LockTaskBarUpdates(ShouldLock: Boolean);


procedure NotifyShell(dwMessage: LongInt);

Send a message to Windows to inform it that we would like to } { add/remove/update our tray icon.

procedure PostEvent(AnEvent: TNotifyEvent);

Used to delay firing an event.

procedure PostEventFromObject(AnEvent: TNotifyEvent; ASender: TObject);

Used to delay firing an event.

procedure Refresh;

Modify some information about the icon that is in the system tray.

procedure RefreshTaskList;


procedure ShowApplication;


procedure ShowForm(const AForm: TForm);

Shows a form, and attempts to stop the Applications taskbar icon } { from showing.

procedure ShowIcon;

Add the icon to the system tray.

function ShowModalForm(const AForm: TForm): Integer;

Shows a form modally, and attempts to stop the Applications taskbar } { icon from showing.

procedure ShowPopupAtCursor;

Displays the popup menu at the current mouse position.

function ApplicationIsHidden: Boolean;


procedure ApplicationMinimize(Sender: TObject);

Minimizes the application to the system tray.

procedure ApplicationRestore(Sender: TObject);

Restores the application from the system tray.

procedure DoFormOnShow(Sender: TObject);


procedure DoHideApplication(Sender: TObject);


procedure DoHideAppTaskBarIcon(Sender: TObject);

Hides the Applications' TaskBar icon.

procedure DoShowApplication(Sender: TObject);


function DoShowForm(const AForm: TForm; const ShowModal: Boolean): Integer;

This function attempts to implement showing a form without having it's } { associated taskbar icon display when shown.

procedure FireEvent(AnEvent:TNotifyEvent);

Fire's an event if it has been defined.

procedure FormOnCloseNotification(Sender: TObject);


function GetClickedMouseButton: TMouseButton;


function GetHandle: THandle;


function GetHint: string;


function HIcon32: LongInt;

This routine is used to get a 32 bit HIcon for the current icon } { being displayed in the system tray.

procedure IconChanged(Sender: TObject);

Update's the icon's display if it is currently being shown } { in the system tray.

procedure LoadAnimationIcon(const AnIconIndex: Integer);

Loads the animation icon corresponding to "AnIconIndex"

procedure LoadCurrentIcon;

Loads the "CurrentIcon" with whichever icon should be displayed in the } { system tray, depending on the current state of the icon.

procedure Loaded;

Used to initially show the TrayIcon if it is supposed to be Active } { on Form Load.

procedure Notification(AComponent: TComponent; Operation: TOperation);


function NotifyOnFormClose(AForm: TForm): Boolean;

Used implicitely to hide a form without showing the Applications TaskBar icon.

procedure SetActive(AnActive: Boolean);

Show/Hide the icon depending on its current value.

procedure SetDisabledIcon(Value: TIcon);


procedure SetHint(Value: string);


procedure SetIcon(Value: TIcon);

Update the hint if it is currently being displayed.

procedure SetOptions(Value: TPGTrayIconOptions);

Notify the icon that it needs to update the display state } { of the hint.

procedure SetShowHint(Value: Boolean);

The second problem is caused by a problem with TrackPopupMenu.

procedure SetState(AState: TPGTrayIconState);


function ShouldDisplayPopup: Boolean;

Returns whether or not the tray icon should display a popup menu } { when the tray icon is "right clicked".

function ShouldDoMouseEnterOrMouseExit: Boolean;

Returns whether or not we should fire the OnMouseEnter/OnMouseLeave events.

function ShouldDoMouseMove: Boolean;

Returns whether or not we should fire the OnMouseMove event.

Properties

property Active : Boolean


property Animation : TPGTrayIconAnimation


property AutoPopup : Boolean


property DisabledIcon : TIcon


property Hint : string


property Icon : TIcon

Store both icon properties before the Active property.

property Options : TPGTrayIconOptions


property PopupMenu : TPopupMenu


property ShowHint : Boolean


property State : TPGTrayIconState


property ClickedMouseButton : TMouseButton


property Form : TForm


property Handle : THandle


property TimerManager : TPGTimerManager


Events

event OnAnimation : TNotifyEvent


event OnAppMinimize : TNotifyEvent


event OnAppRestore : TNotifyEvent


event OnClick : TNotifyEvent


event OnDblClick : TNotifyEvent


event OnMouseEnter : TMouseMoveEvent


event OnMouseExit : TMouseMoveEvent


event OnMouseMove : TMouseMoveEvent


event OnStateChanging : TPGTrayIconStateChangingEvent


Variables

AlreadyShowingForm : Boolean;


ApplicationWasHidden : Boolean;


CurrentIcon : TIcon;


FActive : Boolean;


FAnimation : TPGTrayIconAnimation;


FAutoPopup : Boolean;


FDisabledIcon : TIcon;


FForm : TForm;


FHandle : THandle;


FHint : string;


FIcon : TIcon;


FOnAnimation : TNotifyEvent;


FOnAppMinimize : TNotifyEvent;


FOnAppRestore : TNotifyEvent;


FOnClick : TNotifyEvent;


FOnDblClick : TNotifyEvent;


FOnMouseEnter : TMouseMoveEvent;


FOnMouseExit : TMouseMoveEvent;


FOnMouseMove : TMouseMoveEvent;


FOnStateChanging : TPGTrayIconStateChangingEvent;


FOptions : TPGTrayIconOptions;


FPopupMenu : TPopupMenu;


FShowHint : Boolean;


FState : TPGTrayIconState;


FTimerManager : TPGTimerManager;


MessageWindow : TPGTrayIconMsgWindow;


PostedEvent : TNotifyEvent;


PostedEventSender : TObject;


SaveOnShowEvent : TNotifyEvent;


tnd : PGNOTIFYICONDATA;



Constructors


constructor Create(AOwner: TComponent);

TPGTrayIcon95


Functions


procedure CloseForm(const AForm: TForm);

Closes a form and attempts to stop the Applications taskbar icon } { from showing. You should never need to call this function } { explicitely, since it is implicitely called by the TrayIcon when } { forms that were shown using the ShowModalForm and ShowForm } { are closed.


destructor Destroy;

Replace the Applications's Minimize and Restore events with our own.


procedure DoSetForegroundWindow(Sender: TObject);


procedure HideApplication;

Restore the application if it isn't already restored.


procedure HideIcon;

Remove the icon from the system tray.


procedure LockScreenUpdates(ShouldLock: Boolean);


procedure LockTaskBarUpdates(ShouldLock: Boolean);


procedure NotifyShell(dwMessage: LongInt);

Send a message to Windows to inform it that we would like to } { add/remove/update our tray icon.


procedure PostEvent(AnEvent: TNotifyEvent);

Used to delay firing an event. Sent from Self (ie PGTrayIcon95)


procedure PostEventFromObject(AnEvent: TNotifyEvent; ASender: TObject);

Used to delay firing an event. Sent from any object.


procedure Refresh;

Modify some information about the icon that is in the system tray.


procedure RefreshTaskList;


procedure ShowApplication;


procedure ShowForm(const AForm: TForm);

Shows a form, and attempts to stop the Applications taskbar icon } { from showing.


procedure ShowIcon;

Add the icon to the system tray.


function ShowModalForm(const AForm: TForm): Integer;

Shows a form modally, and attempts to stop the Applications taskbar } { icon from showing.


procedure ShowPopupAtCursor;

Displays the popup menu at the current mouse position.


function ApplicationIsHidden: Boolean;


procedure ApplicationMinimize(Sender: TObject);

Minimizes the application to the system tray.


procedure ApplicationRestore(Sender: TObject);

Restores the application from the system tray.


procedure DoFormOnShow(Sender: TObject);


procedure DoHideApplication(Sender: TObject);


procedure DoHideAppTaskBarIcon(Sender: TObject);

Hides the Applications' TaskBar icon.


procedure DoShowApplication(Sender: TObject);


function DoShowForm(const AForm: TForm; const ShowModal: Boolean): Integer;

This function attempts to implement showing a form without having it's } { associated taskbar icon display when shown. This problem arose in Delphi 3 } { due to some changes Borland made to the Forms.pas file. } { See procedure TApplication.UpdateVisible for more details. It is called whenever } { a form is created, destroyed, hidden or shown, and causes the Application Window } { to reappear in the TaskBar.


procedure FireEvent(AnEvent:TNotifyEvent);

Fire's an event if it has been defined.


procedure FormOnCloseNotification(Sender: TObject);


function GetClickedMouseButton: TMouseButton;


function GetHandle: THandle;


function GetHint: string;


function HIcon32: LongInt;

This routine is used to get a 32 bit HIcon for the current icon } { being displayed in the system tray.


procedure IconChanged(Sender: TObject);

Update's the icon's display if it is currently being shown } { in the system tray.


procedure LoadAnimationIcon(const AnIconIndex: Integer);

Loads the animation icon corresponding to "AnIconIndex"


procedure LoadCurrentIcon;

Loads the "CurrentIcon" with whichever icon should be displayed in the } { system tray, depending on the current state of the icon.


procedure Loaded;

Used to initially show the TrayIcon if it is supposed to be Active } { on Form Load.


procedure Notification(AComponent: TComponent; Operation: TOperation);


function NotifyOnFormClose(AForm: TForm): Boolean;

Used implicitely to hide a form without showing the Applications TaskBar icon.


procedure SetActive(AnActive: Boolean);

Show/Hide the icon depending on its current value.


procedure SetDisabledIcon(Value: TIcon);


procedure SetHint(Value: string);


procedure SetIcon(Value: TIcon);

Update the hint if it is currently being displayed.


procedure SetOptions(Value: TPGTrayIconOptions);

Notify the icon that it needs to update the display state } { of the hint. (i.e. To hide or show the hint as appropriate.)


procedure SetShowHint(Value: Boolean);

The second problem is caused by a problem with TrackPopupMenu. It is necessary } { to force a task switch to the application that called TrackPopupMenu at some } { time in the near future. This can be accomplished by posting a benign message to } { the window or thread.


procedure SetState(AState: TPGTrayIconState);


function ShouldDisplayPopup: Boolean;

Returns whether or not the tray icon should display a popup menu } { when the tray icon is "right clicked".


function ShouldDoMouseEnterOrMouseExit: Boolean;

Returns whether or not we should fire the OnMouseEnter/OnMouseLeave events.


function ShouldDoMouseMove: Boolean;

Returns whether or not we should fire the OnMouseMove event. Note that } { it isn't fired if an event isn't defined, or if we're currently processing } { a click/double click message.


Properties


property Active : Boolean


property Animation : TPGTrayIconAnimation


property AutoPopup : Boolean


property DisabledIcon : TIcon


property Hint : string


property Icon : TIcon

Store both icon properties before the Active property. If they aren't a } { blank icon will be displayed if the component is "Active" on FormLoad.


property Options : TPGTrayIconOptions


property PopupMenu : TPopupMenu


property ShowHint : Boolean


property State : TPGTrayIconState


property ClickedMouseButton : TMouseButton


property Form : TForm


property Handle : THandle


property TimerManager : TPGTimerManager


Events


event OnAnimation : TNotifyEvent


event OnAppMinimize : TNotifyEvent


event OnAppRestore : TNotifyEvent


event OnClick : TNotifyEvent


event OnDblClick : TNotifyEvent


event OnMouseEnter : TMouseMoveEvent


event OnMouseExit : TMouseMoveEvent


event OnMouseMove : TMouseMoveEvent


event OnStateChanging : TPGTrayIconStateChangingEvent


Variables


AlreadyShowingForm : Boolean;


ApplicationWasHidden : Boolean;


CurrentIcon : TIcon;


FActive : Boolean;


FAnimation : TPGTrayIconAnimation;


FAutoPopup : Boolean;


FDisabledIcon : TIcon;


FForm : TForm;


FHandle : THandle;


FHint : string;


FIcon : TIcon;


FOnAnimation : TNotifyEvent;


FOnAppMinimize : TNotifyEvent;


FOnAppRestore : TNotifyEvent;


FOnClick : TNotifyEvent;


FOnDblClick : TNotifyEvent;


FOnMouseEnter : TMouseMoveEvent;


FOnMouseExit : TMouseMoveEvent;


FOnMouseMove : TMouseMoveEvent;


FOnStateChanging : TPGTrayIconStateChangingEvent;


FOptions : TPGTrayIconOptions;


FPopupMenu : TPopupMenu;


FShowHint : Boolean;


FState : TPGTrayIconState;


FTimerManager : TPGTimerManager;


MessageWindow : TPGTrayIconMsgWindow;


PostedEvent : TNotifyEvent;


PostedEventSender : TObject;


SaveOnShowEvent : TNotifyEvent;


tnd : PGNOTIFYICONDATA;