您的位置: 首页 > 软件教程 > Delphi教程专题 > delphi托盘效果实例

delphi托盘效果实例

8.2分
出处:网络 时间:2011-08-05

您可能感兴趣的话题: delphi  

核心提示:delphi相关教程一些相关实例之托盘效果。

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: // 当最小化时

begin

SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,

SWP_HIDEWINDOW);

Hide; // 在任务栏隐藏程序

// 在托盘区显示图标

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 := '托盘程序';

end;

Shell_NotifyIcon(NIM_ADD, @NotifyIcon); // 在托盘区显示图标

end;

else

inherited;

end;

end;

procedure TForm1.WMNID(var msg: TMessage);

var

mousepos: TPoint;

begin

GetCursorPos(mousepos); //获取鼠标位置

case msg.LParam of

WM_LBUTTONUP: // 在托盘区点击左键后

begin

Form1.Visible := not Form1.Visible; // 显示主窗体与否

Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 显示主窗体后删除托盘区的图标

SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW); //

在任务栏显示程序

end;

WM_RBUTTONUP: PopupMenu1.Popup(mousepos.X, mousepos.Y); // 弹出菜单

end;

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删除托盘图标

end;

procedure TForm1.N1Click(Sender: TObject);

begin

Form1.Close;

end;

procedure TForm1.N2Click(Sender: TObject);

begin

Form1.Visible := true; // 显示窗体

SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);

Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删除托盘图标

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

AnimateWindow(Handle,1000,AW_CENTER);//窗口由小变大

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin

AnimateWindow (Handle, 400, AW_HIDE or AW_BLEND);//窗口渐渐消失

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.

网友评论
多特网友 2012-09-23 22:05:23 回复
很好 很经典
多特网友 2012-09-23 22:05:23 回复
很好 很经典
精品软件课程
更多 >
C++是一种静态数据类型检查的,支持多重编程... [详细]
Java,是由Sun Microsystem... [详细]
C语言是一种面向过程的计算机程序设计语言。多... [详细]
Visual Basic是一种由微软公司开发... [详细]
Oracle Database,又名Orac... [详细]
Visual Basic.NET是从 Vis... [详细]