Delphi Tray Effect Example

Source: Internet
Author: User

Unit Unit1;

Interface

Uses

Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,

Dialogs, Shellapi, Appevnts, Stdctrls, Menus;

Const Wm_nid = wm_user + 1000;

Type

TForm1 = Class (Tform)

Popupmenu1:tpopupmenu;

N1:tmenuitem;

N2:tmenuitem;

Label1:tlabel;

Pm1:tpopupmenu;

Mnin3:tmenuitem;

Mnin4:tmenuitem;

Procedure Formdestroy (Sender:tobject);

Procedure N1click (Sender:tobject);

Procedure N2click (Sender:tobject);

Procedure Formcreate (Sender:tobject);

Procedure Formclose (Sender:tobject; var action:tcloseaction);

Procedure Mnin3click (Sender:tobject);

Procedure Mnin4click (Sender:tobject);

Private

{Private declarations}

Procedure Syscommand (var sysmsg:tmessage); Message Wm_syscommand;

Procedure Wmnid (var msg:tmessage); Message Wm_nid;

Public

{Public declarations}

End

Var

Form1:tform1;

Notifyicon:tnotifyicondata;

Implementation

{$R *.DFM}

{TForm1}

Procedure Tform1.syscommand (var sysmsg:tmessage);

Begin

Case Sysmsg.wparam of

Sc_minimize://When minimized

Begin

SetWindowPos (Application.handle, hwnd_notopmost, 0, 0, 0, 0,

Swp_hidewindow);

Hide; Hiding programs in the taskbar

Show icon in tray area

With NotifyIcon do

Begin

cbsize: = SizeOf (Tnotifyicondata);

WND: = Handle;

UID: = 1;

Uflags: = Nif_icon or nif_message or nif_tip;

Ucallbackmessage: = Wm_nid;

Hicon: = Application.Icon.Handle;

Sztip: = ' pallet procedure ';

End

Shell_NotifyIcon (Nim_add, @NotifyIcon); Show icon in tray area

End

Else

inherited;

End

End

Procedure Tform1.wmnid (var msg:tmessage);

Var

Mousepos:tpoint;

Begin

GetCursorPos (Mousepos); Get mouse position

Case Msg. LParam of

Wm_lbuttonup://After clicking left button in pallet area

Begin

Form1.visible: = Not form1.visible; Show main form or not

Shell_NotifyIcon (Nim_delete, @NotifyIcon); Icon to delete pallet area after displaying main form

SetWindowPos (Application.handle, hwnd_top, 0, 0, 0, 0, Swp_showwindow); //

displaying programs in the taskbar

End

WM_RBUTTONUP:PopupMenu1.Popup (Mousepos. X, Mousepos. Y); pop-up menu

End

End

Procedure Tform1.formdestroy (Sender:tobject);

Begin

Shell_NotifyIcon (Nim_delete, @NotifyIcon); Remove tray icon

End

Procedure Tform1.n1click (Sender:tobject);

Begin

Form1.close;

End

Procedure Tform1.n2click (Sender:tobject);

Begin

Form1.visible: = true; Show form

SetWindowPos (Application.handle, hwnd_top, 0, 0, 0, 0, Swp_showwindow);

Shell_NotifyIcon (Nim_delete, @NotifyIcon); Remove tray icon

End

Procedure Tform1.formcreate (Sender:tobject);

Begin

AnimateWindow (handle,1000,aw_center);//window from small to large

End

Procedure Tform1.formclose (Sender:tobject; var action:tcloseaction);

Begin

AnimateWindow (Handle, aw_hide or aw_blend);/The Window fades away

End

Procedure Tform1.mnin3click (Sender:tobject);

Begin

Form1.close;

End

Procedure Tform1.mnin4click (Sender:tobject);

Begin

ShellExecute (handle, ' open ', ' http://www.aheasy.cn ', nil,nil,sw_show);

End

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.