请问在delphi中,把一个窗口变成一个图标放在任务栏右角上,要用到什么函数。 在Shell32.DLL动态链接库中包括一个函数Shell_NotifyIconA()可通知Windows在任务条右下角加入一个小图标, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 系统托盘它是通过调用shellapi函数shell_NotifyIcon()来完成的。Shell_NotifyIcon函数的TNotifyIconData结构定义如下:cbsize:结构的尺寸;Wnd :应用程序的句柄,一般为=Handle;uID : 应用程序定义的在托盘中图标的ID,可以任意选择,一般为0;uFlags :指定可用项,有NIF_ICON、NIF_TIP、NIF_MESSAGE;uCallbackMessage :指定回调函数;hIcon :指定托盘图标,一般为=Icon.Handle;szTip :提示信息;Shell_NotifyIcon函数的使用:Shell_NotifyIcon(dwMessage:Cardinal,pData:pNotifyIconData):dwMessage:要执行操作的标志ID[NIM_ADD、NIM_DELETE、NIM_MODIFY];pData:上面所写的结构的指针[@nid];添加系统托盘的全部过程:1.自定义消息:Const WM_MYMSG=WM_USER+100;2.定义消息回调函数:procedure MyFunc(var msg:Tmessage);message WM_MYMSG;3.在FormCreate函数中添加结构成员,然后调用函数;4.隐藏窗体:在FormPaint函数中调用Hide方法;5.在FormClose函数中调用API函数取消托盘程序; Look:// 也可去搜索呀unit Unit_Shell;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI, ExtCtrls, Menus;Const WM_TRayMessage=WM_user+10;type TForm1 = class(TForm) PopupMenu1: TPopupMenu; aaa1: TMenuItem; bbb1: TMenuItem; ccc1: TMenuItem; ddd1: TMenuItem; Image1: TImage; Procedure WMTrayMessage(Var Msg:TMessage);Message WM_Traymessage; Procedure AppMiniMized(Sender:TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; Nid:TNotifyIconData;implementation{$R *.dfm}Procedure Tform1.WMTrayMessage(Var Msg:TMessage); Var PMouse:TPoint; Begin If Msg.LParam=WM_LButtonDBLclk Then Begin ShowWindow(Application.Handle,SW_Show); Application.Restore ; End Else If Msg.LParam=WM_RButtonDown Then Begin GetCursorPos(PMouse); PoPupMenu1.Popup(PMouse.X,Pmouse.Y) End; End;Procedure TForm1.AppMiniMized(Sender:TObject); Begin Nid.cbSize:=Sizeof(TNotifyIconData); Nid.hIcon:=Image1.Picture.Icon.Handle ; Nid.szTip:='测试系统'; Nid.uCallbackMessage:=WM_TrayMessage; Nid.uFlags:=Nif_Icon or Nif_Message OR Nif_Tip; Nid.Wnd:=Handle; Nid.uID:=0; Shell_NotifyIcon(Nim_add,@Nid); ShowWindow(Application.Handle,SW_Hide); end;procedure TForm1.FormCreate(Sender: TObject);begin Application.OnMinimize:=AppMiniMized; AppMiniMized(Nil);end;procedure TForm1.FormDestroy(Sender: TObject);begin Shell_NotifyIcon(Nim_Delete,@Nid);end;end. 这是我原来写的程序 Const WM_ICONCALLBACKMESSAGE=WM_USER+0; tind:TNotifyIconData; procedure WndProc (var Message:TMessage);message WM_iconcallbackMessage; //这里是定义tind.cbSize:=SizeOf (TNotifyIconData); tind.Wnd:=form1.Handle; tind.hIcon:=Application.Icon.Handle; tind.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE; tind.uID:=0; tind.szTip:='测试'; tind.uCallBackMessage:=WM_ICONCALLBACKMESSAGE;shell_NotifyIcon (NIM_ADD,@tind);shell_NotifyIcon (NIM_delete,@tind); procedure WndProc (var Message:TMessage); //这里是截获消息if msg.LParam=WM_LButtonDown then //如果是左健 begin ShowWindow(Application.Handle,SW_Show); Application.Restore; end else if msg.LParam=WM_RButtonDown then //如果是右健 begin GetCursorPos(p); PopupMenu1.Popup(p.x,p.y); end; 如何向ACCESS添加大量数据 问个简单的小问题 让程序在U盘中自动运行 编译时没有问题,但是在delphi中按F9时,就会出错 在线等待,解决就结贴2 2003高考试题 今天无意间发现了一个BUG! 初学者的非常菜的问题,很急!!!!!!!!! 求助:Delphi程序嵌套C#界面,消息问题 两个地方下载的fastreport都提示fr_class.duc找不到,请问在哪里能载到没有问题的?? 在delphi6下采用DBcomboBox组合框显示某字段数据的时候只有一条而不能下拉??? 我真菜,这么简单的CheckBox问题都不懂
它是通过调用shellapi函数shell_NotifyIcon()来完成的。Shell_NotifyIcon函数的TNotifyIconData结构定义如下:
cbsize:结构的尺寸;
Wnd :应用程序的句柄,一般为=Handle;
uID : 应用程序定义的在托盘中图标的ID,可以任意选择,一般为0;
uFlags :指定可用项,有NIF_ICON、NIF_TIP、NIF_MESSAGE;
uCallbackMessage :指定回调函数;
hIcon :指定托盘图标,一般为=Icon.Handle;
szTip :提示信息;
Shell_NotifyIcon函数的使用:Shell_NotifyIcon(dwMessage:Cardinal,pData:pNotifyIconData):
dwMessage:要执行操作的标志ID[NIM_ADD、NIM_DELETE、NIM_MODIFY];
pData:上面所写的结构的指针[@nid];
添加系统托盘的全部过程:
1.自定义消息:Const WM_MYMSG=WM_USER+100;
2.定义消息回调函数:procedure MyFunc(var msg:Tmessage);message WM_MYMSG;
3.在FormCreate函数中添加结构成员,然后调用函数;
4.隐藏窗体:在FormPaint函数中调用Hide方法;
5.在FormClose函数中调用API函数取消托盘程序;
unit Unit_Shell;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellAPI, ExtCtrls, Menus;Const
WM_TRayMessage=WM_user+10;type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
aaa1: TMenuItem;
bbb1: TMenuItem;
ccc1: TMenuItem;
ddd1: TMenuItem;
Image1: TImage;
Procedure WMTrayMessage(Var Msg:TMessage);Message WM_Traymessage;
Procedure AppMiniMized(Sender:TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Nid:TNotifyIconData;implementation{$R *.dfm}
Procedure Tform1.WMTrayMessage(Var Msg:TMessage);
Var
PMouse:TPoint;
Begin
If Msg.LParam=WM_LButtonDBLclk Then
Begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore ;
End
Else If Msg.LParam=WM_RButtonDown Then
Begin
GetCursorPos(PMouse);
PoPupMenu1.Popup(PMouse.X,Pmouse.Y)
End;
End;Procedure TForm1.AppMiniMized(Sender:TObject);
Begin
Nid.cbSize:=Sizeof(TNotifyIconData);
Nid.hIcon:=Image1.Picture.Icon.Handle ;
Nid.szTip:='测试系统';
Nid.uCallbackMessage:=WM_TrayMessage;
Nid.uFlags:=Nif_Icon or Nif_Message OR Nif_Tip;
Nid.Wnd:=Handle;
Nid.uID:=0;
Shell_NotifyIcon(Nim_add,@Nid);
ShowWindow(Application.Handle,SW_Hide);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=AppMiniMized;
AppMiniMized(Nil);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(Nim_Delete,@Nid);
end;end.
tind:TNotifyIconData;
procedure WndProc (var Message:TMessage);message WM_iconcallbackMessage; //这里是定义
tind.cbSize:=SizeOf (TNotifyIconData);
tind.Wnd:=form1.Handle;
tind.hIcon:=Application.Icon.Handle;
tind.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
tind.uID:=0;
tind.szTip:='测试';
tind.uCallBackMessage:=WM_ICONCALLBACKMESSAGE;
shell_NotifyIcon (NIM_ADD,@tind);
shell_NotifyIcon (NIM_delete,@tind); procedure WndProc (var Message:TMessage); //这里是截获消息if msg.LParam=WM_LButtonDown then //如果是左健
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end
else if msg.LParam=WM_RButtonDown then //如果是右健
begin
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;