Tutorial kali ini saya posting mengenai Minimize Tray Icon di delphi, Tray icon biasanya ada pada sudut bawah taskbar windows berdekatan dengan jam di komputer. Pengen kan kalau bisa minimize program tapi bisa ke tray icon.. untuk menghemat tempat di taskbar windows. Langsung saja Ke Tutorialnya
Langkah Pertama Buka Aplikasi Delphi
- New application
- save all
- simpan pada folder yg telah ditentukan
Langkah Kedua Tambahkan Komponen
- Button
- Popupmenu
Langkah Ketiga Masukan Listing Code Programnya
Pada Uses Paling Atas Tambahkan
ShellApi;
Seperti contoh dibawah ini
Tambahkan
procedure WM_CALLBACKPRO(var msg : TMessage); message wm_callBack;
Seperti contoh dibawah ini
Kemudian Tambahkan
var
kecil : HICON;
TrayIcon : TNotifyIconData;
Seperti dibawah ini
Kemudian Tambahkan
Uses comobj;
Uses comobj;
Kemudian Tambahkan
procedure TForm1.WM_CALLBACKPRO(var msg : TMessage);
var
p : TPoint;
begin
case msg.LParam of
WM_LBUTTONDOWN :
begin
Shell_NotifyIcon(NIM_DELETE,@TrayIcon);
Form1.Visible := True;
end;
WM_RBUTTONDOWN :
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
end;
end;
p : TPoint;
begin
case msg.LParam of
WM_LBUTTONDOWN :
begin
Shell_NotifyIcon(NIM_DELETE,@TrayIcon);
Form1.Visible := True;
end;
WM_RBUTTONDOWN :
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
end;
end;
Kemudian tambahkan lagi pada button click
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Visible := False;
Kecil := application.Icon.Handle;
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := handle;
Trayicon.szTip := 'Aplikasi Tray Icon // Double Click For Show';
Trayicon.uID := 1;
TrayIcon.hIcon := Kecil;
TrayIcon.uCallbackMessage := WM_CAllBack;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@trayicon);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Visible := False;
Kecil := application.Icon.Handle;
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := handle;
Trayicon.szTip := 'Aplikasi Tray Icon // Double Click For Show';
Trayicon.uID := 1;
TrayIcon.hIcon := Kecil;
TrayIcon.uCallbackMessage := WM_CAllBack;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@trayicon);
end;
Kemudian tambahkan pada Close di popupmenu1
procedure TForm1.Close1Click(Sender: TObject);
begin
Halt;
end;
begin
Halt;
end;
Kemudian tambahkan pada About di popupmenu1
procedure TForm1.Show1Click(Sender: TObject);
begin
ShowMessage('Aplikasi Tray Icon');
end;
begin
ShowMessage('Aplikasi Tray Icon');
end;
Selesai deh... Silahkan Run dengan Ctrl F9 (untuk menditeksi Error) Lalu Tekan F9
Untuk listing code lengkapnya dibawah ini :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, acPNG, StdCtrls, XPMan, Menus, ShellApi;
Const
WM_CAllBack = WM_USER;
type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
Panel1: TPanel;
Button1: TButton;
Label1: TLabel;
Image1: TImage;
Label2: TLabel;
Bevel1: TBevel;
Label3: TLabel;
Timer1: TTimer;
PopupMenu1: TPopupMenu;
Show1: TMenuItem;
N6: TMenuItem;
Close1: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure Show1Click(Sender: TObject);
procedure WM_CALLBACKPRO(var msg : TMessage); message wm_callBack;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
kecil : HICON;
TrayIcon : TNotifyIconData;
implementation
Uses comobj;
procedure TForm1.WM_CALLBACKPRO(var msg : TMessage);
var
p : TPoint;
begin
case msg.LParam of
WM_LBUTTONDOWN :
begin
Shell_NotifyIcon(NIM_DELETE,@TrayIcon);
Form1.Visible := True;
end;
WM_RBUTTONDOWN :
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
end;
end;
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption:=TimeToStr(now);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Visible := False;
Kecil := application.Icon.Handle;
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := handle;
Trayicon.szTip := 'Aplikasi Tray Icon // Double Click For Show';
Trayicon.uID := 1;
TrayIcon.hIcon := Kecil;
TrayIcon.uCallbackMessage := WM_CAllBack;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@trayicon);
end;
procedure TForm1.Close1Click(Sender: TObject);
begin
Halt;
end;
procedure TForm1.Show1Click(Sender: TObject);
begin
ShowMessage('Aplikasi Tray Icon');
end;
end.
Untuk listing code lengkapnya dibawah ini :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, acPNG, StdCtrls, XPMan, Menus, ShellApi;
Const
WM_CAllBack = WM_USER;
type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
Panel1: TPanel;
Button1: TButton;
Label1: TLabel;
Image1: TImage;
Label2: TLabel;
Bevel1: TBevel;
Label3: TLabel;
Timer1: TTimer;
PopupMenu1: TPopupMenu;
Show1: TMenuItem;
N6: TMenuItem;
Close1: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure Show1Click(Sender: TObject);
procedure WM_CALLBACKPRO(var msg : TMessage); message wm_callBack;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
kecil : HICON;
TrayIcon : TNotifyIconData;
implementation
Uses comobj;
procedure TForm1.WM_CALLBACKPRO(var msg : TMessage);
var
p : TPoint;
begin
case msg.LParam of
WM_LBUTTONDOWN :
begin
Shell_NotifyIcon(NIM_DELETE,@TrayIcon);
Form1.Visible := True;
end;
WM_RBUTTONDOWN :
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
end;
end;
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption:=TimeToStr(now);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Visible := False;
Kecil := application.Icon.Handle;
Trayicon.cbSize := SizeOf(TNotifyIconData);
Trayicon.Wnd := handle;
Trayicon.szTip := 'Aplikasi Tray Icon // Double Click For Show';
Trayicon.uID := 1;
TrayIcon.hIcon := Kecil;
TrayIcon.uCallbackMessage := WM_CAllBack;
Trayicon.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,@trayicon);
end;
procedure TForm1.Close1Click(Sender: TObject);
begin
Halt;
end;
procedure TForm1.Show1Click(Sender: TObject);
begin
ShowMessage('Aplikasi Tray Icon');
end;
end.
Sign up here with your email
ConversionConversion EmoticonEmoticon