关于系统托盘有这种控件,所以这点我就不说了。关于最小话,这个问题要截断系统消息,
procedure TWMSysCommand(var Msg:TMessage ); message wm_SysCommand;
procedure TfrmSrvMain.TWMSysCommand(var Msg:TMessage );
begin
case Msg.WParam of
SC_MINIMIZE:
begin
if (Self.Visible=true)and(not isClose) then
begin
btnMid.SetFocus;
Self.Hide;
FillDataStructure;
Shell_NotifyIcon(NIM_Add,@IconData);
end
else
inherited;
end
else
inherited;
end;
end;
procedure TWMSysCommand(var Msg:TMessage ); message wm_SysCommand;
procedure TfrmSrvMain.TWMSysCommand(var Msg:TMessage );
begin
case Msg.WParam of
SC_MINIMIZE:
begin
if (Self.Visible=true)and(not isClose) then
begin
btnMid.SetFocus;
Self.Hide;
FillDataStructure;
Shell_NotifyIcon(NIM_Add,@IconData);
end
else
inherited;
end
else
inherited;
end;
end;
WM_TrayMessage=WM_User+100; protected
procedure AppMinimized(Sender: TObject);
procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;uses ShellApivar
NID:TNotifyIconData{点击了任务栏的图标}
procedure TMainForm.WMTrayMessage(var msg:TMessage);
var
p:TPoint;
begin
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); //获取光标位置
pmTray.Popup(p.x,p.y); //显示弹出菜单
end;
end;{应用程序最小化时图标显示在任务栏}
procedure TMainForm.AppMinimized(Sender:TObject);
begin
NID.cbSize:=SizeOf(TNotifyIconData);
NID.hIcon:=Application.Icon.Handle;
NID.szTip:= 'taxi';
NID.uCallbackMessage:=WM_TrayMessage;
NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
NID.uID:=0;
NID.Wnd:=Handle;
Shell_NotifyIcon(NIM_ADD,@NID);
ShowWindow(Application.Handle,SW_Hide);
end;procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=AppMinimized;
AppMinimized(nil);
end;procedure TMainForm.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NID);
end;
2、可以用winexec or ShellExecute 来条用外部程序
如:
winexec('http://www.microsoft.com',SW_SHOWNORMAL)
type
TForm1 = class(TForm)
private
procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
procedure WMBarIcon(var Message:TMessage);message WM_BARICON;procedure TForm1.WMSysCommand(var Message:TMessage);
var
lpData:PNotifyIconData;
begin
if Message.WParam = SC_ICON then
begin //如果用户最小化窗口则将窗口 隐藏并在任务栏上添加图标
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88; //SizeOf(PNotifyIconDataA);
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
Form1.Visible := False;
end
else
begin //如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。
DefWindowProc(Form1.Handle,Message.Msg,Message.WParam,Message.LParam);
end;
end;procedure TForm1.WMBarIcon(var Message:TMessage);
var
lpData:PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) then
begin //如果用户点击任务栏图标则将图标删除并回复窗口。
lpData := new(PNotifyIconDataA);
lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);
lpData.Wnd := Form1.Handle;
lpData.hIcon := Form1.Icon.Handle;
lpData.uCallbackMessage := WM_BARICON;
lpData.uID :=0;
lpData.szTip := 'Samples';
lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_DELETE,lpData);
dispose(lpData);
Form1.Visible := True;
end;
end;
能完成你所要求的功能 2. 用ShellExecute(Handle,'open',PChar('http://www.microsoft.com'),nil,nil,SW_SHOWNORMAL);
要在uses中加上ShellAPI
var
IconData: TNotifyIconData;
begin
TestIcon := TIcon.Create;
TestIcon.LoadFromFile('Snow.ico');
iconData.cbSize := sizeof(icondata);
iconData.Wnd := Handle;
IconData.uID := 1;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallBackMessage := WM_USER + 1;
IconData.hIcon := Testicon.Handle;
IconData.szTip := '这是一个任务栏测试!';
Shell_NotifyIcon( NIM_ADD, @IconData );
end;那个'Snow.ico'你自己改一下吧