托盘的代码如下,请各位帮忙看看: procedure TForm_main.FormCreate(Sender: TObject); with NotifyIcon do begin cbsize:=sizeof(TNotifyIconData); Wnd:=Handle; uID:=1; uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP; uCallbackMessage:=WM_NID; hIcon:=Application.icon.Handle; szTip:='CDMA无线网卡应用管理器'; end; shell_NotifyIcon(NIM_ADD,@NotifyIcon); end;Procedure Tform_main.WMSysCommand(var msg:Tmessage); begin if msg.WParam=SC_Minimize then begin //Form_main.Visible :=false; Form_main.Left :=screen.Width; showwindow(application.Handle ,SW_HIDE); end else if msg.WParam =SC_CLOSE then begin close; end; end;Procedure Tform_main.WMNID(var msg:Tmessage); var p:Tpoint; begin case msg.LParam of WM_LBUTTONUP: begin if Form_main.left<>screen.Width then begin form_main.Left :=screen.Width ; showwindow(application.Handle ,SW_HIDE); end else begin Getcursorpos(p); PopupMenu1.Popup(P.X,p.Y ); //form_main.Left :=(Screen.Width div 2)-(form_main.Width div 2); //showwindow(application.Handle ,SW_RESTORE); end; end; //Form_main.Visible :=not Form_main.Visible ; WM_RBUTTONUP: begin Getcursorpos(p); PopupMenu1.Popup(P.X,p.Y ); end; end; end;procedure TForm_main.FormDestroy(Sender: TObject); begin Shell_NotifyIcon(NIM_DELETE,@NotifyIcon); end;
代码就是上面这样的,写完后,托盘是有了,不过主窗口也不能动了.是不是API本身的问题呀?
應該是這一句有問題: Procedure Tform_main.WMSysCommand(var msg:Tmessage); begin if msg.WParam=SC_Minimize then begin //Form_main.Visible :=false; Form_main.Left :=screen.Width; showwindow(application.Handle ,SW_HIDE); end else if msg.WParam =SC_CLOSE then begin close; end; end;上面完成後沒有交還給delphi;
Procedure Tform_main.WMSysCommand(var msg:Tmessage); begin if msg.WParam=SC_Minimize then begin //Form_main.Visible :=false; Form_main.Left :=screen.Width; showwindow(application.Handle ,SW_HIDE); end else if msg.WParam =SC_CLOSE then begin close; end; inherited;//添加這句試一試 end;
procedure TForm_main.FormCreate(Sender: TObject);
with NotifyIcon do
begin
cbsize:=sizeof(TNotifyIconData);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallbackMessage:=WM_NID;
hIcon:=Application.icon.Handle;
szTip:='CDMA无线网卡应用管理器';
end;
shell_NotifyIcon(NIM_ADD,@NotifyIcon);
end;Procedure Tform_main.WMSysCommand(var msg:Tmessage);
begin
if msg.WParam=SC_Minimize then
begin
//Form_main.Visible :=false;
Form_main.Left :=screen.Width;
showwindow(application.Handle ,SW_HIDE);
end else if msg.WParam =SC_CLOSE then
begin
close;
end;
end;Procedure Tform_main.WMNID(var msg:Tmessage);
var
p:Tpoint;
begin
case msg.LParam of
WM_LBUTTONUP:
begin
if Form_main.left<>screen.Width then
begin
form_main.Left :=screen.Width ;
showwindow(application.Handle ,SW_HIDE);
end else
begin
Getcursorpos(p);
PopupMenu1.Popup(P.X,p.Y );
//form_main.Left :=(Screen.Width div 2)-(form_main.Width div 2);
//showwindow(application.Handle ,SW_RESTORE);
end; end;
//Form_main.Visible :=not Form_main.Visible ;
WM_RBUTTONUP:
begin
Getcursorpos(p);
PopupMenu1.Popup(P.X,p.Y );
end;
end;
end;procedure TForm_main.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
end;
Procedure Tform_main.WMSysCommand(var msg:Tmessage);
begin
if msg.WParam=SC_Minimize then
begin
//Form_main.Visible :=false;
Form_main.Left :=screen.Width;
showwindow(application.Handle ,SW_HIDE);
end else if msg.WParam =SC_CLOSE then
begin
close;
end;
end;上面完成後沒有交還給delphi;
begin
if msg.WParam=SC_Minimize then
begin
//Form_main.Visible :=false;
Form_main.Left :=screen.Width;
showwindow(application.Handle ,SW_HIDE);
end else if msg.WParam =SC_CLOSE then
begin
close;
end;
inherited;//添加這句試一試
end;
是这样子的,我加了这句就好了,谢谢