Arsip: Menempatkan Icon dalam System Tray


by marvel in Articles more 14 years ago 2019
Skrip-skrip berikut digunakan untuk menempatkan ikon di SystemTray, sorry kalo masih ada kesalahan2 pada koding ini
uses
..., ShellAPI;
const
WM_ICONTRAY = WM_USER + 1; //User-defined message

type
...
var
...
NotifyIconData   : TNotifyIconData;
implementation
procedure Tfrmmain.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);
setwindowlong(application.Handle, gwl_exstyle,ws_ex_toolwindow);
end;
Syntax Highlighted with https://pascal-id.org/syntax

-code diatas digunakan untuk memunculkan icon pada objectinspector Form1
-tambahkan popupmenu untuk listing code dibawah ini
-jangan lupa icon nya dikasih gambar yah... kalo nga nti binggung...


procedure tfrmmain.icontray(var Msg: Tmessage);
var
cursorpos : tpoint;
begin
if msg.LParam = wm_rbuttondown then
begin
getcursorpos(cursorpos);
popupmenu1.Popup(cursorpos.X,cursorpos.Y);
end else
inherited;
end;
Syntax Highlighted with https://pascal-id.org/syntax

-menampilkan dan menyembunyikan form
-tambahkan Exit dan Show pada item di popupmenu


procedure Tfrmmain.Show1Click(Sender: TObject);
begin
;
//shell_notifyicon(nim_delete,@notifyicondata);
end;
procedure Tfrmmain.Exit1Click(Sender: TObject);
begin
shell_notifyicon(nim_delete,@notifyicondata);
application.ProcessMessages;
application.Terminate;
end;
procedure Tfrmmain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action  := canone;
hide;
//shell_notifyicon(nim_add,@notifyicondata);
end;
Syntax Highlighted with https://pascal-id.org/syntax
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com