jongwee Moderator
Reputation: 0
Joined: 28 Jun 2006 Posts: 1388 Location: Singapore
|
Posted: Sun Oct 28, 2007 9:24 pm Post subject: [Delphi]Create an Icon in System Tray[/Delphi] |
|
|
| Code: |
....
Const
WM_ICONTRAY = WM_USER + 1;
Private
procedure Icontray(var Msg: TMessage); message WM_ICONTRAY;
procedure TForm1.FormCreate(Sender: TObject);
begin
with NotifyIconData do begin
hIcon := Icon.Handle;
StrPCopy(szTip, Application.Title);
Wnd := Handle;
uCallbackMessage := WM_ICONTRAY;
uID := 1;
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
cbSize := sizeof(TNotifyIconData);
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIconData);
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_SHOW);
end;
procedure TForm1.Icontray(var Msg: TMessage);
var
CursorPos : TPoint;
begin
if Msg.lParam = WM_RBUTTONDOWN then begin
GetCursorPos(CursorPos);
SetForegroundWindow(Handle); // suggested by Berend Radstaat
PopupMenu1.Popup(CursorPos.x, CursorPos.y);
PostMessage(Handle, WM_NULL, 0, 0); // suggested by Berend Radstaat
end else
inherited;
end;
|
2) Go to your Project Manager, right click on your whatever.exe and select "View Source"
| Code: |
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.Run;
end.
|
I'm not sure if the second step is necessary but just add it in case. If there is any thing I havent added, please tell me. Thanks!
_________________
|
|