Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

[Share] cara buat tray icon delphi

#1

[Only registered and activated users can see links Click here to register]


dibawah ini source code beserta tampilan script lengkapnya

script lengkap :

Pada Unit Exe :

program Tray_Icon;
//==========================================================//
//copyright : [Only registered and activated users can see links Click here to register] //
// [Only registered and activated users can see links Click here to register] //
//==========================================================//

uses
Forms,
Controls, Dialogs, ShellApi, Windows, // <<<<<<<<< uses yg diperlukan
UTrayIcon in 'UTrayIcon.pas' {TrayIcon};

{$R *.res}
var
NotifyIconData : TNotifyIconData;
begin
Application.Initialize;
Application.ShowMainForm := true; // fungsi untuk pada saat run Munculkan Form atau tidak nilai True berarti Muncul dan False berarti Hide
Application.Title := 'Open Aplikasi Tray Icon';
Application.CreateForm(TTrayIcon, TrayIcon);
NotifyIconData.cbSize := SizeOf( NotifyIconData );
NotifyIconData.Wnd := Trayicon.Handle;
NotifyIconData.uCallbackMessage := WM_ShellIcon;
NotifyIconData.hIcon := Application.Icon.Handle;
NotifyIconData.szTip := 'Open Aplikasi Tray Icon';
NotifyIconData.uFlags := NIF_TIP + NIF_MESSAGE + NIF_ICON;
try
Shell_NotifyIcon( NIM_ADD, @NotifyIconData );
ShowWindow(Application.Handle, SW_HIDE);
Application.Run;
finally
Shell_NotifyIcon( NIM_DELETE, @NotifyIconData );
end;
end.
=====================end Code===================

Pada Form Unit:

unit UTrayIcon;
//==========================================================//
//copyright : [Only registered and activated users can see links Click here to register] //
// [Only registered and activated users can see links Click here to register] //
//==========================================================//

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ExtCtrls,Shellapi, ComCtrls, ImgList;

const
WM_ShellIcon = WM_USER + 1;

type
TTrayIcon = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
Restore1: TMenuItem;
Hide1: TMenuItem;
N2: TMenuItem;
Exit1: TMenuItem;
N3: TMenuItem;
httpolvandrablogspotcom1: TMenuItem;
Label1: TLabel;
Image1: TImage;
StatusBar1: TStatusBar;
ImageList1: TImageList;
procedure FormActivate(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Restore1Click(Sender: TObject);
procedure Hide1Click(Sender: TObject);
procedure httpolvandrablogspotcom1Click(Sender: TObject);
private
{ Private declarations }
procedure O_nsShellIcon( var Msg : TMessage ); message WM_ShellIcon;
procedure O_nsMinimize( var Msg : TWMSysCommand ); message WM_SYSCOMMAND;
public
{ Public declarations }
end;

var
TrayIcon: TTrayIcon;

implementation

{$R *.dfm}

//script Button minimize = SC_MINIMIZE : //script tombol Close = SC_CLOSE
//jika Button Minimize di tekan
procedure TTrayIcon.O_nsMinimize(var Msg: TWMSysCommand);
begin
if( Msg.CmdType = SC_MINIMIZE ) then // ScMINIMIZE bisa di ganti dengan SC_CLOSE
Hide
else
inherited;
end;

//script create Tray icon dan Popupmenu
procedure TTrayIcon.O_nsShellIcon(var Msg: TMessage);
var
O_ns : TPoint;
begin
case Msg.LParam of
WM_LBUTTONDBLCLK : begin
Show;
SetForegroundWindow( Handle );
end;
WM_RBUTTONUP : begin
SetForegroundWindow( Handle );
GetCursorPos( O_ns );
PopupMenu1.Popup( O_ns.x, O_ns.y );
PostMessage( Handle, WM_USER, 0, 0 );
end;
end;
end;

//script untuk hidden Form di TASKBAR saat run(Sw_showmodal atau Sw_Hide)
procedure TTrayIcon.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE); // Sw-Hide bisa diganti dengan Sw_Showmodal ;
end;

//script untuk menghentikan program
procedure TTrayIcon.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;

//script untuk memunculkan Form pada Popupmenu
procedure TTrayIcon.Restore1Click(Sender: TObject);
begin
Show;
SetForegroundWindow( Handle );
end;

//script untuk sembuntikan Form pada popupmenu
procedure TTrayIcon.Hide1Click(Sender: TObject);
begin
Hide;
end;

//script untuk memanggil link (tambahkan shellapi pada uses paling atas)
procedure TTrayIcon.httpolvandrablogspotcom1Click(Sender: TObject);
begin
ShellExecute(Application.handle, 'open', 'http://olvandra.blogspot.com', nil, nil,
SW_ShowNormal);
end;
end.

klow belum ngerti om ini source code dbawah
Register or login to see this content
ahminblack, proud to be a member of ForNesia Family since Mar 2014.
Reply
#2
Thread Copas ya mbah ? Google itu haha
qibIP, Copyright©2014, All Right Reserved

[Only registered and activated users can see links Click here to register]
Reply
#3
harusnya komponen juga di share, gak jalan kalo komponen gak ada..
Reply
#4
cara ganti icon nya itu gimana ya?
yang ijo kuning merah itu?
Reply
#5
(12-28-2014, 03:01 PM)risvhal Wrote: harusnya komponen juga di share, gak jalan kalo komponen gak ada..

gak perlu komponen gan...cuma segitu codingnya

(12-28-2014, 03:47 PM)bayputra Wrote: cara ganti icon nya itu gimana ya?
yang ijo kuning merah itu?
itu setting pda popupmenu gan...
sprti ini gan
[Image: phphd182y.jpg]
Reply
#6
Itu pada unit exe masukkin nya gimana gan?
“Jangan tanyakan apa yang telah diberikan negara padamu, tapi tanyakan apa yang telah kamu berikan untuk negara”
Reply
#7
kepanjangan codenya ini mbah, kn tujuan intinya adalah membuat TrayIcon, itupun make komponen buahaha
tinggal ambil intinya aja, biar gk trlalu bingung lihatnya sm penerapannya ketawaaa
[Only registered and activated users can see links Click here to register]
Reply
#8
sebenarnya pake komponen cooltray juga bisa malah lebih simpel ^_^
Reply
  


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SHARE] Cara Install Componen Zeos Pada Delphi Auryn 3 1,042 04-05-2016, 10:53 PM
Last Post: saling percaya
  [SHARE] cara membuat teks berjalan di form delphi jack 6 1,701 08-31-2014, 05:22 PM
Last Post: justlab