uses ShellAPI;<br><br>var<br> hw : Thandle;<br> procid : DWORD;<br> threadid : DWORD;<br> nid: TNotifyIconData;<br>begin<br> hw := findwindow(pChar(Edit1.text),nil);<br> if hw <> 0 then<br> begin<br>// showmessage('found');<br> threadid := getwindowthreadprocessid(hw,@procid);<br> procid := OpenProcess(PROCESS_TERMINATE,false,procid);<br> //postmessage(hw,WM_QUIT,0,0); <br> nid.cbSize := sizeof(nid);<br> nid.uID := 1;//内部标识,与加入小图标时的数一致,不然需鼠标移过去才消失。<br> nid.Wnd := hw; //主窗口句柄<br> Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br> TerminateProcess(procid,0);<br> end;<br>end;<br><br>有的也可以这样关闭:<br>var<br> hw : Thandle;<br>begin<br> hw := findwindow(pChar(Edit1.text),nil);<br> if hw <> 0 then<br> begin<br> postmessage(hw,WM_quit,0,0);<br> end;<br>end;