如何在我的程序里关闭QQ2003?(200分)

  • 主题发起人 主题发起人 mayi
  • 开始时间 开始时间
M

mayi

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个小程序,需要判断QQ2003是否打开并关闭它,但我用<br>SendMessage(hWndClose, WM_CLOSE, 0, 0);//hWndClose为QQ2003的句柄<br>结果不行,用另外一句为<br>postmessage(hWndClose,wm_QUIT,1,1);<br>结果只把QQ2003最小化,而没有关闭;最后用TerminateProcess的方式关闭,这回倒是可以了,但却在任务栏上留下QQ的图标,需用鼠标移到图标上方才会消失,哪位高手帮忙解决一下,送上200大分,如果不够,另外加分也可以,先说明QQ版本必须为QQ2003,其它版本无效。
 
procedure Kill_QQ2003_Process;<br>var <br>&nbsp; PID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br>&nbsp; SmW &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :string;<br>&nbsp; BRet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Boolean;<br>&nbsp; tmp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :string;<br>&nbsp; SnapshotHandle &nbsp;:THandle;<br>&nbsp; PE32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:TProcessEntry32;<br>&nbsp; Hmb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :HWND;<br>begin<br>&nbsp; SmW := lowercase('qq.exe');<br>&nbsp; SnapshotHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>&nbsp; PE32.dwSize := SizeOf(PE32);<br>&nbsp; BRet:=Process32First(SnapshotHandle, PE32);<br>&nbsp; while Integer(BRet) &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; tmp:=lowercase(PE32.szExeFile);<br>&nbsp; &nbsp; &nbsp; if pos(SmW,tmp)&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PID := PE32.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hmb:= OpenProcess(PROCESS_ALL_ACCESS, True,PID);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TerminateProcess(Hmb,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; BRet:=Process32Next(SnapshotHandle,PE32);<br>&nbsp; &nbsp; end;<br>end;<br>直接删除qq的进程,结束他。
 
To netwatch:<br>这个方法我也用过了,是可以关闭QQ2003,但任务栏上的QQ图标却还在,需手工移动鼠标到图标的上方,图标才会消失,这个问题怎么解决呢?这个很重要的。
 
SendMessage(Handle,WM_CLOSE,0,0)<br>Handle为QQ的Handle <br>你可以用Delphi自带的WinSight32查看QQ的Handle<br>保你成功。
 
to netwatch,请问,您写的这些代码都要用到哪些单元???
 
用此函数,是我自家产的:<br>function KillTask(ExeFileName: string): integer;<br>const<br>&nbsp; &nbsp;PROCESS_TERMINATE=$0001;<br>var<br>&nbsp; ContinueLoop: BOOL;<br>&nbsp; FSnapshotHandle: THandle;<br>&nbsp; FProcessEntry32: TProcessEntry32;<br>begin<br>&nbsp; result := 0;<br>&nbsp; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br>&nbsp; ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);<br>&nbsp; while integer(ContinueLoop) &lt;&gt; 0 do begin<br>&nbsp; &nbsp; if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName))<br>&nbsp; &nbsp;or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) then<br>&nbsp; &nbsp; &nbsp;Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));<br>&nbsp; &nbsp; &nbsp;ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);<br>&nbsp; end;<br>&nbsp; CloseHandle(FSnapshotHandle);<br>end;
 
To yu_ting:<br>我用QQ2003Ⅱ beta2+Delphi6+Win2000里试了,不行啊,还是只能中止程序,但任务栏上的图标还是不能删除,需移动鼠标到图标上方才会消失的,各位应该试一下自已的代码,然后再发表的。
 
Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),1));//改成1试试<br>&nbsp; &nbsp;
 
自已解决了,感谢各位参与,分还是要给的。
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2532183
 
刷新一下
 
将鼠标指针移到托盘区再移回来呢
 
用程序监视进度,如果进程为QQ.exe,就关掉<br><br>
 
主要是关闭之后要刷新状态栏!
 
mayi,你自己是怎么解决的,我也在寻求这个问题的解决方法
 
晕,以下是做好了的.把它们加到你自己的工程里就行了.<br><br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=2587881
 
应该可以在进程里面杀掉吧。。。
 
杀掉进程是没问题,主要问题是在任务栏上留有图标,需移动鼠标到上方后,才会消失。各位的代码我都试过,但没一个能解决任务栏上的图标问题,各位难道没有试过吗?看看右下角的任务栏是不是还有QQ的图标,在你杀掉QQ的进程后。
 
话题1228942的标题是: About:任务栏图标
 

Similar threads

D
回复
0
查看
928
DelphiTeacher的专栏
D
D
回复
0
查看
883
DelphiTeacher的专栏
D
D
回复
0
查看
856
DelphiTeacher的专栏
D
后退
顶部