[453] | 1 | { **************************************************************
|
---|
| 2 | Package: XWB - Kernel RPCBroker
|
---|
| 3 | Date Created: Sept 18, 1997 (Version 1.1)
|
---|
| 4 | Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
|
---|
| 5 | Developers: Kevin Meldrum, Travis Hilton, Joel Ivey
|
---|
| 6 | Description: Basic form for RPCSharedBrokerSessionMgr1.exe.
|
---|
| 7 | Current Release: Version 1.1 Patch 40 (January 7, 2005))
|
---|
| 8 | *************************************************************** }
|
---|
| 9 |
|
---|
| 10 | unit fVistaBar;
|
---|
| 11 |
|
---|
| 12 | interface
|
---|
| 13 |
|
---|
| 14 | uses
|
---|
| 15 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
| 16 | Buttons, StdCtrls, ExtCtrls, Menus, ShellAPI;
|
---|
| 17 |
|
---|
| 18 | const
|
---|
| 19 | {Support SysTray}
|
---|
| 20 | wm_IconNotification = wm_User + 100; //System Tray Msg Handle
|
---|
| 21 | ICON_OFF = 100; //IconId for not connected icon
|
---|
| 22 | ICON_ON = 101; //IconId for connected icon
|
---|
| 23 | ICON_OFF_TIP = 'RPCSharedBrokerSessionMgr: no connections'; //Tip when not connected
|
---|
| 24 | ICON_ON_TIP = 'RPCSharedBrokerSessionMgr'; //Tip when connected
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | type
|
---|
| 29 | TfrmVistABar = class(TForm)
|
---|
| 30 | pmnSysTray: TPopupMenu;
|
---|
| 31 | About1: TMenuItem;
|
---|
| 32 |
|
---|
| 33 | procedure FormActivate(Sender: TObject);
|
---|
| 34 | procedure FormCreate(Sender: TObject);
|
---|
| 35 | function AddTrayIcon(iconId : UINT; icon : THandle; tip : string)
|
---|
| 36 | : Boolean;
|
---|
| 37 | function DeleteTrayIcon(iconId : UINT) : Boolean;
|
---|
| 38 | procedure FormDestroy(Sender: TObject);
|
---|
| 39 | procedure Exit1Click(Sender: TObject);
|
---|
| 40 | procedure About1Click(Sender: TObject);
|
---|
| 41 | private
|
---|
| 42 | { Private declarations }
|
---|
| 43 | NotifyIconData : TNOTIFYICONDATA;
|
---|
| 44 | TrayIconId : UINT;
|
---|
| 45 | TrayIcon : HICON;
|
---|
| 46 | TrayTip : string;
|
---|
| 47 | protected
|
---|
| 48 | procedure WMIconNotification(var Msg : TMessage);
|
---|
| 49 | message wm_IconNotification;
|
---|
| 50 | procedure wmQueryEndSession(var Msg : TMessage);
|
---|
| 51 | message wm_QueryEndSession;
|
---|
| 52 | public
|
---|
| 53 | { Public declarations }
|
---|
| 54 | end;
|
---|
| 55 |
|
---|
| 56 | var
|
---|
| 57 | frmVistABar: TfrmVistABar;
|
---|
| 58 |
|
---|
| 59 | implementation
|
---|
| 60 |
|
---|
| 61 | uses uSharedBroker1, frmVistAAbout;
|
---|
| 62 |
|
---|
| 63 | {$R *.DFM}
|
---|
| 64 | {$R *.RES}
|
---|
| 65 |
|
---|
| 66 | procedure TfrmVistABar.FormActivate(Sender: TObject);
|
---|
| 67 | begin
|
---|
| 68 | ShowWindow(Application.Handle, SW_HIDE);
|
---|
| 69 | Top := 0;
|
---|
| 70 | Left := (Screen.Width - Width) div 2;
|
---|
| 71 |
|
---|
| 72 | // Is there a better way to hide this window?
|
---|
| 73 | // Visible := false; // doesn't work
|
---|
| 74 | // TODO
|
---|
| 75 | // Find a way to make the main form non visible
|
---|
| 76 | Width := 0;
|
---|
| 77 | Height := 0;
|
---|
| 78 |
|
---|
| 79 | end;
|
---|
| 80 |
|
---|
| 81 | procedure TfrmVistABar.FormCreate(Sender: TObject);
|
---|
| 82 | var
|
---|
| 83 | I: Integer;
|
---|
| 84 | begin
|
---|
| 85 | for I := 1 to ParamCount do // Iterate
|
---|
| 86 | if UpperCase(ParamStr(I)) = 'REGISTER' then
|
---|
| 87 | Halt;
|
---|
| 88 | {Setup NotifyIconData fields that won't change}
|
---|
| 89 | NotifyIconData.cbSize := SizeOf(TNOTIFYICONDATA);
|
---|
| 90 | NotifyIconData.Wnd := Handle;
|
---|
| 91 | NotifyIconData.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
|
---|
| 92 | NotifyIconData.uCallbackMessage := wm_IconNotification;
|
---|
| 93 |
|
---|
| 94 | {Setup initial icon (= NotConnected) and add it!}
|
---|
| 95 | TrayIconId := ICON_ON;
|
---|
| 96 | TrayIcon := LoadIcon(HInstance, 'ICON_ON'); //Loads icon from resource.
|
---|
| 97 | TrayTip := ICON_ON_TIP;
|
---|
| 98 | AddTrayIcon(TrayIconId, TrayIcon, TrayTip);
|
---|
| 99 | SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
|
---|
| 100 | //ShowWindow(Application.Handle, SW_HIDE);
|
---|
| 101 | end;
|
---|
| 102 |
|
---|
| 103 | function TfrmVistaBar.AddTrayIcon(iconId : UINT; icon : THandle; tip : string)
|
---|
| 104 | : Boolean;
|
---|
| 105 | begin
|
---|
| 106 | NotifyIconData.uID := IconID;
|
---|
| 107 | NotifyIconData.HIcon := icon;
|
---|
| 108 | if tip <> '' then
|
---|
| 109 | StrLCopy(NotifyIconData.szTip, PChar(tip), SizeOf(NotifyIconData.szTip))
|
---|
| 110 | else
|
---|
| 111 | NotifyIconData.szTip := #0;
|
---|
| 112 | Result := Shell_NotifyIcon(NIM_ADD, @NotifyIconData);
|
---|
| 113 | end;
|
---|
| 114 |
|
---|
| 115 | {Processes messages to the icon in the System Tray.}
|
---|
| 116 | procedure TfrmVistaBar.WMIconNotification(var Msg : TMessage);
|
---|
| 117 | var
|
---|
| 118 | MouseMsg : LongInt;
|
---|
| 119 | Pt: TPoint;
|
---|
| 120 | begin
|
---|
| 121 | MouseMsg := Msg.LParam;
|
---|
| 122 |
|
---|
| 123 | case MouseMsg of
|
---|
| 124 | wm_LButtonDown :
|
---|
| 125 | ;
|
---|
| 126 | wm_RButtonUp :
|
---|
| 127 | begin
|
---|
| 128 | GetCursorPos(Pt); //Used to locate pop-up menu
|
---|
| 129 | pmnSysTray.PopUp(Pt.X, Pt.Y); //Displays menu
|
---|
| 130 | end;
|
---|
| 131 | wm_LButtonDblClk : //DoubleClick displays form.
|
---|
| 132 | // mitShowClick(Self);
|
---|
| 133 | end;
|
---|
| 134 | end;
|
---|
| 135 |
|
---|
| 136 | {Event handler sets flag used in FormCloseQuery so that user is }
|
---|
| 137 | procedure TfrmVistaBar.wmQueryEndSession(var Msg : TMessage);
|
---|
| 138 | begin
|
---|
| 139 | // CanAutoClose := True;
|
---|
| 140 | Msg.Result := 1;
|
---|
| 141 | end;
|
---|
| 142 |
|
---|
| 143 | function TfrmVistaBar.DeleteTrayIcon(iconId : UINT) : Boolean;
|
---|
| 144 | begin
|
---|
| 145 | NotifyIconData.uID := IconID;
|
---|
| 146 | Result := Shell_NotifyIcon(NIM_DELETE, @ NotifyIconData);
|
---|
| 147 | Application.ProcessMessages;
|
---|
| 148 | end;
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | procedure TfrmVistABar.FormDestroy(Sender: TObject);
|
---|
| 153 | begin
|
---|
| 154 | DeleteTrayIcon(TrayIconId);
|
---|
| 155 | end;
|
---|
| 156 |
|
---|
| 157 | procedure TfrmVistABar.Exit1Click(Sender: TObject);
|
---|
| 158 | begin
|
---|
| 159 | ShowMessage('If the system warns against closing this Application - DON''T CLOSE IT.#13#10Closing this when it shouldn''t be will cause any applications using it to crash');
|
---|
| 160 | Halt;
|
---|
| 161 | end;
|
---|
| 162 |
|
---|
| 163 | procedure TfrmVistABar.About1Click(Sender: TObject);
|
---|
| 164 | begin
|
---|
| 165 | ShowAboutBox;
|
---|
| 166 | end;
|
---|
| 167 |
|
---|
| 168 | end.
|
---|