1.第一个问题 Tmainform = class(TForm) PopupMenu1: TPopupMenu; N7: TMenuItem; private { Private declarations } procedure mymessage(var message:tmessage);message mymsg; public { Public declarations } end; var mainform: Tmainform;ntid:tnotifyicondataa; procedure TForm1.mymessage(var message:tmessage); var mypt:tpoint; begin inherited; if message.lparam=wm_rbuttonup then begin getcursorpos(mypt); popupmenu1.popup(mypt.x,mypt.y);//弹出菜单 end else begin if message.LParam=WM_LBUTTONDBLCLK then begin //执行你的命令 end; end; message.Result:=0; end;procedure Tmainform.FormCreate(Sender: TObject); var zappname:array[0..127] of char; hold:string; found:hwnd; begin ntid.cbSize:=sizeof(tnotifyicondataa); ntid.Wnd:=handle; ntid.uID:=iid; ntid.uFlags:=nif_icon+nif_tip+nif_message; ntid.uCallbackMessage:=mymsg; ntid.hIcon:=application.Icon.handle; ntid.szTip:='{你要显示的文本}'; shell_notifyicona(NIM_ADD,@ntid); end;
1.第一个问题 Tmainform = class(TForm) PopupMenu1: TPopupMenu; N7: TMenuItem; private { Private declarations } procedure mymessage(var message:tmessage);message mymsg; public { Public declarations } end; var mainform: Tmainform;ntid:tnotifyicondataa; procedure TForm1.mymessage(var message:tmessage); var mypt:tpoint; begin inherited; if message.lparam=wm_rbuttonup then begin getcursorpos(mypt); popupmenu1.popup(mypt.x,mypt.y);//弹出菜单 end else begin if message.LParam=WM_LBUTTONDBLCLK then begin //执行你的命令 end; end; message.Result:=0; end;procedure Tmainform.FormCreate(Sender: TObject); var zappname:array[0..127] of char; hold:string; found:hwnd; begin ntid.cbSize:=sizeof(tnotifyicondataa); ntid.Wnd:=handle; ntid.uID:=iid; ntid.uFlags:=nif_icon+nif_tip+nif_message; ntid.uCallbackMessage:=mymsg; ntid.hIcon:=application.Icon.handle; ntid.szTip:='{你要显示的文本}'; shell_notifyicona(NIM_ADD,@ntid); end;
用findwindow找窗体句柄,用进程关闭,postmessage(handle,wm_close,0,0);只是发送关闭消息,用进程关闭时强行关闭,一定能关得了: var H:THandle;//窗口句柄 P:DWORD; str: string;//窗口名称 begin Str := 'Project1';//改成你要的名字 H:=FindWindow(nil,pchar(Str)); if H<>0 then begin GetWindowThreadProcessId(H,@P); if P<>0 then TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF); end; end; ...str是窗体名字
2:找到那个程序句柄,发消息就是了,如
postmessage(handle,wm_close,0,0);
你可以用 delphi中带的WinSight32工具来看程序的句丙
里面有解决办法
Tmainform = class(TForm)
PopupMenu1: TPopupMenu;
N7: TMenuItem;
private
{ Private declarations }
procedure mymessage(var message:tmessage);message mymsg;
public
{ Public declarations }
end;
var
mainform: Tmainform;ntid:tnotifyicondataa;
procedure TForm1.mymessage(var message:tmessage);
var mypt:tpoint;
begin
inherited;
if message.lparam=wm_rbuttonup then
begin
getcursorpos(mypt);
popupmenu1.popup(mypt.x,mypt.y);//弹出菜单
end
else
begin
if message.LParam=WM_LBUTTONDBLCLK then
begin
//执行你的命令
end;
end;
message.Result:=0;
end;procedure Tmainform.FormCreate(Sender: TObject);
var
zappname:array[0..127] of char;
hold:string;
found:hwnd;
begin
ntid.cbSize:=sizeof(tnotifyicondataa);
ntid.Wnd:=handle;
ntid.uID:=iid;
ntid.uFlags:=nif_icon+nif_tip+nif_message;
ntid.uCallbackMessage:=mymsg;
ntid.hIcon:=application.Icon.handle;
ntid.szTip:='{你要显示的文本}';
shell_notifyicona(NIM_ADD,@ntid);
end;
Tmainform = class(TForm)
PopupMenu1: TPopupMenu;
N7: TMenuItem;
private
{ Private declarations }
procedure mymessage(var message:tmessage);message mymsg;
public
{ Public declarations }
end;
var
mainform: Tmainform;ntid:tnotifyicondataa;
procedure TForm1.mymessage(var message:tmessage);
var mypt:tpoint;
begin
inherited;
if message.lparam=wm_rbuttonup then
begin
getcursorpos(mypt);
popupmenu1.popup(mypt.x,mypt.y);//弹出菜单
end
else
begin
if message.LParam=WM_LBUTTONDBLCLK then
begin
//执行你的命令
end;
end;
message.Result:=0;
end;procedure Tmainform.FormCreate(Sender: TObject);
var
zappname:array[0..127] of char;
hold:string;
found:hwnd;
begin
ntid.cbSize:=sizeof(tnotifyicondataa);
ntid.Wnd:=handle;
ntid.uID:=iid;
ntid.uFlags:=nif_icon+nif_tip+nif_message;
ntid.uCallbackMessage:=mymsg;
ntid.hIcon:=application.Icon.handle;
ntid.szTip:='{你要显示的文本}';
shell_notifyicona(NIM_ADD,@ntid);
end;
var H:THandle;//窗口句柄
P:DWORD;
str: string;//窗口名称
begin
Str := 'Project1';//改成你要的名字
H:=FindWindow(nil,pchar(Str));
if H<>0 then
begin
GetWindowThreadProcessId(H,@P);
if P<>0 then
TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF);
end;
end;
...str是窗体名字