如何才能像其它软件一样在最小化是在系统托盘上出现一个可控制的图标?
请高手指教,不胜感激~!~
请高手指教,不胜感激~!~
解决方案 »
- 请帮我看看这两个是哪种条码?
- 如何HOOK自身的系统API?
- QR问题,大家帮忙!!
- 如何隔行改变dbgrid的颜色,如何插入图片到dbgrid?
- 高手帮忙!关于delphi的调试工具CODEsite的用法?
- 散分:delphi报表工具的疑问
- 我想做一个知识管理的东东,各位大侠有什么好的经验传授。来者有分
- 哪里可以下载到delphi6中文企业版,谢谢!
- 如何给某种类型的文件注册一种图标,然后指定打开该类型的文件的默认程序
- 请问哪里有下介绍server页控件的书可以下载?
- 如何做到拖运窗体时窗体跟着动,而不是显示窗体的虚线框?
- 怎样编程实现在没安装acrobat reader的机器上正常打开pdf文件?
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi;const MY_MESSAGE = WM_USER + 100;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);
message MY_MESSAGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnIconNotify(var Message: TMessage);
var
Busy: Boolean;
begin
busy:=false;
if not Busy then
begin
busy := true;
if Message.LParam=WM_LBUTTONDOWN then
if Application.MessageBox('Are you sure','Exit',
MB_YESNO)=IDYES then Close;
Busy := false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := Handle; // 主窗口句柄
nid.uID :=1; // 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
nid.szTip := 'This is a test application'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?
if not Shell_NotifyIcon(NIM_ADD,@nid) then
begin
ShowMessage('Failed!');
Application.Terminate;
end;
{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := 1; //内部标识,与加入小图标时的数一致
nid.Wnd := Handle; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Hide;
end;
end.
ShellAPI;
const
CICON_ID = 1;
NIM_CALLBACKMSG = WM_USER + 100; procedure InstallNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string); stdcall;
procedure ModifyNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string); stdcall;
procedure UninstallNotifyIcon(const ParentWnd: HWND; const AIconID: UINT); stdcall;implementationprocedure InstallNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string);
var
NID: TNotifyIconData;
uLen: Byte;
begin
if Length(ATip) > 64 then
uLen := 64
else
uLen := Length(ATip); NID.cbSize := SizeOf(TNotifyIconData);
NID.Wnd := ParentWnd;
NID.uID := AIconID;
NID.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
NID.uCallbackMessage := ACallBackMsg;
NID.hIcon := AIcon.Handle;
Move(Pointer(ATip)^, NID.szTip, uLen); Shell_NotifyIcon(NIM_ADD, @NID);
end;procedure ModifyNotifyIcon(const ParentWnd: HWND; AIcon: TIcon;
const AIconID: UINT; const ACallBackMsg: UINT; const ATip: string);
var
NID: TNotifyIconData;
uLen: Byte;
begin
if Length(ATip) > 64 then
uLen := 64
else
uLen := Length(ATip); NID.cbSize := SizeOf(TNotifyIconData);
NID.Wnd := ParentWnd;
NID.uID := AIconID;
NID.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
NID.uCallbackMessage := ACallBackMsg;
NID.hIcon := AIcon.Handle;
Move(Pointer(ATip)^, NID.szTip, uLen); Shell_NotifyIcon(NIM_MODIFY, @NID);
end;procedure UninstallNotifyIcon(const ParentWnd: HWND; const AIconID: UINT);
var
NID: TNotifyIconData;
begin
NID.cbSize := SizeOf(TNotifyIconData);
NID.Wnd := ParentWnd;
NID.uID := AIconID; Shell_NotifyIcon(NIM_DELETE, @NID);
end;