Tray Icon dgn Tombol Minimize [ Delphi 7 ]

 
Sesuai Permintaan saya post tutorial Tray Icon dengan Tombol Minimize [ Delphi 7 ], kronologinya pada saat tombol minimize windows di klik pada program biasanya hanya minimize pada taskbar saja, sekarang kita ubah dimana pada saat tombol minimize di klik akan masuk ke system trayiscon. langsung ke tutorial :

 dibawah ini source code beserta tampilan script lengkapnya


script lengkap :

Pada Unit Exe :                                              

program Tray_Icon;
//==========================================================//
//copyright : http://olvandra.blogspot.com                  //
//            http://meanddelphi.blogspot.com               //
//==========================================================//

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 : http://olvandra.blogspot.com                  //
//            http://meanddelphi.blogspot.com               //
//==========================================================//

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.

Download Tutorial format Doc

4shared : Download

Download Source code Tray Icon Dengan Minimize:

Mediafire : Download

4shared : Download

6 thoughts on “Tray Icon dgn Tombol Minimize [ Delphi 7 ]

  1. mantaap om.. ijin donlod deh :D

    BalasHapus
  2. mas SC save, save as dan save default itu kaya gmn ya?

    BalasHapus
    Balasan
    1. maksudnya gimana nya ya,,?kurang jelas kronologinya mas.

      Penggunaannya? Atau Fungsinya? komponent apa?

      Hapus
  3. Website paling ternama dan paling terpercaya di Asia
    Sistem pelayanan 24 Jam Non-Stop bersama dengan CS Berpengalaman respon tercepat
    Memiliki 9 Jenis game yang sangat digemari oleh seluruh peminat poker / domino
    Link Alternatif :
    arena-domino.club
    arena-domino.vip
    100% Memuaskan ^-^

    BalasHapus
  4. gan, try iconya gak muncul, kira2 yg kurang apanya ya?

    BalasHapus

Silahkan Tulis Komentar Anda, Sopan dan Berwibawa