delphi(api)系统托盘
2008-09-25 12:31
190 查看
好简单的一个事例啊,昨天翻下上去几年的资料,找到的这个。
//delphi用API制作的系统托盘加弹出菜单, 用了将近两年的。NET再看下这个有点感觉不同
//也是以前开发时常用的这种方法
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls, Menus;
const wm_icon = WM_USER + 100;
type
TForm1 = class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure user_sysmenu(var msg:twmmenuselect); message WM_COMMAND;
private
{ Private declarations }
procedure OnIconNotify(var Message: TMessage); message wm_icon;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.user_sysmenu(var msg:twmmenuselect);//处理弹出菜单的选择项
begin
if msg.IDItem =999 then
self.Close
else
inherited;
end;
procedure tform1.OnIconNotify(var Message: TMessage); //处理程序提示区图标 消息
var
menu:HMENU;
rect:trect;
pp:tpoint;
begin
if Message.LParam =WM_RBUTTONDOWN then
begin
rect.Left:=56;
rect.Top:=0;
rect.Right:=100;
rect.Bottom:=88;
//rect.BottomRight:= point(LOWORD(message.lParam),HIWORD(message.lParam));
menu:=createpopupmenu();
appendmenu(menu,MF_STRING,999,'exit');
GetCursorPos ( pp);//current mouse postion
TrackPopupMenu(menu, TPM_LEFTALIGN , pp.x , pp.y ,0,self.Handle,@rect);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
cc:TNotifyIconData ;
begin
cc.cbSize:= sizeof(cc);
cc.Wnd:= self.Handle;
cc.uID := 1;
cc.hIcon := Application.Icon.Handle; // 窗口句柄
cc.szTip := 'This is a test application' ;
cc.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效
cc.uCallbackMessage:= wm_icon ; //处理的消息
Shell_NotifyIcon(NIM_ADD, @cc); // destroy window NIM_DELETE + index
end;
end.
//delphi用API制作的系统托盘加弹出菜单, 用了将近两年的。NET再看下这个有点感觉不同
//也是以前开发时常用的这种方法
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls, Menus;
const wm_icon = WM_USER + 100;
type
TForm1 = class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure user_sysmenu(var msg:twmmenuselect); message WM_COMMAND;
private
{ Private declarations }
procedure OnIconNotify(var Message: TMessage); message wm_icon;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.user_sysmenu(var msg:twmmenuselect);//处理弹出菜单的选择项
begin
if msg.IDItem =999 then
self.Close
else
inherited;
end;
procedure tform1.OnIconNotify(var Message: TMessage); //处理程序提示区图标 消息
var
menu:HMENU;
rect:trect;
pp:tpoint;
begin
if Message.LParam =WM_RBUTTONDOWN then
begin
rect.Left:=56;
rect.Top:=0;
rect.Right:=100;
rect.Bottom:=88;
//rect.BottomRight:= point(LOWORD(message.lParam),HIWORD(message.lParam));
menu:=createpopupmenu();
appendmenu(menu,MF_STRING,999,'exit');
GetCursorPos ( pp);//current mouse postion
TrackPopupMenu(menu, TPM_LEFTALIGN , pp.x , pp.y ,0,self.Handle,@rect);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
cc:TNotifyIconData ;
begin
cc.cbSize:= sizeof(cc);
cc.Wnd:= self.Handle;
cc.uID := 1;
cc.hIcon := Application.Icon.Handle; // 窗口句柄
cc.szTip := 'This is a test application' ;
cc.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效
cc.uCallbackMessage:= wm_icon ; //处理的消息
Shell_NotifyIcon(NIM_ADD, @cc); // destroy window NIM_DELETE + index
end;
end.
相关文章推荐
- Win32 API 实现系统托盘程序
- Delphi 7下最小化到系统托盘
- Win32 API 实现系统托盘程序
- Delphi 利用注册表和API取WIN系统下硬件信息
- Delphi 添加系统托盘
- Delphi 7下最小化到系统托盘
- 【Win32 API】在系统托盘显示图标和弹出气泡
- Win32 API 实现系统托盘程序
- Delphi中实现系统托盘的功能
- Delphi 7下最小化到系统托盘(主要是WM_TRAYMSG和WM_SYSCOMMAND消息)
- Delphi实现系统托盘图标
- Delphi中如何让窗口最小化至系统托盘
- Delphi 7下最小化到系统托盘
- 使用Win32 API做个系统托盘图标
- 使用Win32 API做个系统托盘图标
- Win32 API 实现系统托盘程序
- Delphi 添加系统托盘
- 用J2SE6.0试用 - 用新增API实现TrayIcon系统托盘图标
- 使用Win32 API做个系统托盘图标
- DELPHI 系统托盘