Shell_NotifyIcon這個API可以實現系統托盤圖示功能,然後你在自定義一下最小化的訊息就可以了,圖示功能有個例子
托盤就是在工作列右下角的小圖示。建立、更改、刪除只需要一個WindowsAPI就能實現。這個函式叫做Shell_NotifyIcon()。這個函式和其他處理Windows外殼的函式都包含在ShellAPI單元中。本例程在視窗建立時在工作列的右下角建立一個托盤圖示。圖示由兩個ICON交替出現。當視窗最小化時工作列中只有托盤圖示,當左鍵單擊托盤圖示視窗恢復。圖示停止交替。
unitUnit1;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,SHELLAPI,
Menus,Dialogs,
ExtCtrls,ImgList;
const
MI_ICONEVENT=WM_USER+1;
ICON_ID=10;
type
TForm1=class(TForm)
Timer1:TTimer;
PopupMenu2:TPopupMenu;
N1:TMenuItem;
ImageList1:TImageList;
procedureN1Click(Sender:TObject);
procedureFormCreate(Sender:TObject);
procedureFormDestroy(Sender:TObject);
procedureFormClose(Sender:TObject;varAction:TCloseAction);
procedureTimer1Timer(Sender:TObject);
private
proceduremodifyicon;
procedureIconOnClick(varmessage:TMessage);MESSAGEMI_ICONEVENT;
proceduretranmessage(varm:TWMSYSCOMMAND);messageWM_SYSCOMMAND;
public
{Publicdeclarations}
end;
var
Form1:TForm1;
ydic:array[0..1]ofticon;
icint:integer;
xsyc:BOOLEAN;
implementation
{$R*.DFM}
procedureTForm1.N1Click(Sender:TObject);
begin
APPLICATION.Terminate;
procedureTForm1.FormCreate(Sender:TObject);
IconData:TNotifyIconData;
xsyc:=true;
ydic[0]:=ticon.Create;
ydic[1]:=ticon.Create;
ydic[0].Handle:=loadicon(hinstance,"icon0");//資原始檔(ICONS.RES)
ydic[1].Handle:=loadicon(hinstance,"icon1");
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
IconData.uFlags:=NIF_ICONorNIF_MESSAGEorNIF_TIP;
IconData.uCallBackMessage:=MI_ICONEVENT;
IconData.hIcon:=ydic[0].Handle;
IconData.szTip:="我笑、我笑、笑笑笑";
icint:=0;
Shell_NotifyIcon(NIM_ADD,@IconData);
ShowWindow(Application.Handle,SW_HIDE);
procedureTForm1.FormDestroy(Sender:TObject);
begin//解除安裝圖示
Shell_NotifyIcon(NIM_DELETE,@IconData);
procedureTForm1.FormClose(Sender:TObject;varAction:TCloseAction);
procedureTForm1.Timer1Timer(Sender:TObject);
modifyicon
procedureTForm1.modifyicon;
icint:=(icint+1)mod2;
icondata.hIcon:=ydic[icint].Handle;
shell_notifyicon(nim_modify,@icondata);
procedureTForm1.IconOnClick(varmessage:TMessage);
a:tpoint;
begin//單擊事件
if(message.lParam=WM_RBUTTONDOWN)then
getcursorpos(a);
PopupMenu2.Popup(a.x,a.y);
end
elseif(message.lParam=WM_LBUTTONDOWN)then
timer1.Enabled:=FALSE;
ifxsycthen
sendmessage(form1.Handle,wm_syscommand,sc_minimize,0)
else
ShowWindow(Application.Handle,SW_RESTORE);//SW_maximize
setforegroundwindow(form1.handle);
procedureTForm1.tranmessage(varm:TWMSYSCOMMAND);
ifm.CmdType=SC_MINIMIZEthen
timer1.Enabled:=true;
sendmessage(Application.Handle,WM_SYSCOMMAND,SC_MINimize,0);
xsyc:=false;
inherited;
end.
最小化訊息過載可以這樣
procedurepgame(varmsg:twmsyscommand);messagewm_syscommand;
procedureTmainfrm.pgame(varmsg:twmsyscommand);//視窗最小化
ifmsg.CmdType=SC_MINIMIZEthen
//處理程式碼
Shell_NotifyIcon這個API可以實現系統托盤圖示功能,然後你在自定義一下最小化的訊息就可以了,圖示功能有個例子
托盤就是在工作列右下角的小圖示。建立、更改、刪除只需要一個WindowsAPI就能實現。這個函式叫做Shell_NotifyIcon()。這個函式和其他處理Windows外殼的函式都包含在ShellAPI單元中。本例程在視窗建立時在工作列的右下角建立一個托盤圖示。圖示由兩個ICON交替出現。當視窗最小化時工作列中只有托盤圖示,當左鍵單擊托盤圖示視窗恢復。圖示停止交替。
unitUnit1;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,SHELLAPI,
Menus,Dialogs,
ExtCtrls,ImgList;
const
MI_ICONEVENT=WM_USER+1;
ICON_ID=10;
type
TForm1=class(TForm)
Timer1:TTimer;
PopupMenu2:TPopupMenu;
N1:TMenuItem;
ImageList1:TImageList;
procedureN1Click(Sender:TObject);
procedureFormCreate(Sender:TObject);
procedureFormDestroy(Sender:TObject);
procedureFormClose(Sender:TObject;varAction:TCloseAction);
procedureTimer1Timer(Sender:TObject);
private
proceduremodifyicon;
procedureIconOnClick(varmessage:TMessage);MESSAGEMI_ICONEVENT;
proceduretranmessage(varm:TWMSYSCOMMAND);messageWM_SYSCOMMAND;
public
{Publicdeclarations}
end;
var
Form1:TForm1;
ydic:array[0..1]ofticon;
icint:integer;
xsyc:BOOLEAN;
implementation
{$R*.DFM}
procedureTForm1.N1Click(Sender:TObject);
begin
APPLICATION.Terminate;
end;
procedureTForm1.FormCreate(Sender:TObject);
var
IconData:TNotifyIconData;
begin
xsyc:=true;
ydic[0]:=ticon.Create;
ydic[1]:=ticon.Create;
ydic[0].Handle:=loadicon(hinstance,"icon0");//資原始檔(ICONS.RES)
ydic[1].Handle:=loadicon(hinstance,"icon1");
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
IconData.uFlags:=NIF_ICONorNIF_MESSAGEorNIF_TIP;
IconData.uCallBackMessage:=MI_ICONEVENT;
IconData.hIcon:=ydic[0].Handle;
IconData.szTip:="我笑、我笑、笑笑笑";
icint:=0;
Shell_NotifyIcon(NIM_ADD,@IconData);
ShowWindow(Application.Handle,SW_HIDE);
end;
procedureTForm1.FormDestroy(Sender:TObject);
var
IconData:TNotifyIconData;
begin//解除安裝圖示
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
procedureTForm1.FormClose(Sender:TObject;varAction:TCloseAction);
var
IconData:TNotifyIconData;
begin//解除安裝圖示
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
procedureTForm1.Timer1Timer(Sender:TObject);
begin
modifyicon
end;
procedureTForm1.modifyicon;
var
IconData:TNotifyIconData;
begin
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
icint:=(icint+1)mod2;
IconData.uFlags:=NIF_ICONorNIF_MESSAGEorNIF_TIP;
IconData.uCallBackMessage:=MI_ICONEVENT;
icondata.hIcon:=ydic[icint].Handle;
IconData.szTip:="我笑、我笑、笑笑笑";
shell_notifyicon(nim_modify,@icondata);
end;
procedureTForm1.IconOnClick(varmessage:TMessage);
var
a:tpoint;
begin//單擊事件
if(message.lParam=WM_RBUTTONDOWN)then
begin
getcursorpos(a);
PopupMenu2.Popup(a.x,a.y);
end
elseif(message.lParam=WM_LBUTTONDOWN)then
begin
timer1.Enabled:=FALSE;
ifxsycthen
sendmessage(form1.Handle,wm_syscommand,sc_minimize,0)
else
begin
ShowWindow(Application.Handle,SW_RESTORE);//SW_maximize
setforegroundwindow(form1.handle);
xsyc:=true;
end;
end;
end;
procedureTForm1.tranmessage(varm:TWMSYSCOMMAND);
begin
ifm.CmdType=SC_MINIMIZEthen
begin
timer1.Enabled:=true;
sendmessage(Application.Handle,WM_SYSCOMMAND,SC_MINimize,0);
ShowWindow(Application.Handle,SW_HIDE);
xsyc:=false;
end
else
inherited;
end;
end.
最小化訊息過載可以這樣
procedurepgame(varmsg:twmsyscommand);messagewm_syscommand;
procedureTmainfrm.pgame(varmsg:twmsyscommand);//視窗最小化
begin
ifmsg.CmdType=SC_MINIMIZEthen
begin
//處理程式碼
end;
inherited;
end;