结束程序(50分)

  • 主题发起人 主题发起人 一生骄傲
  • 开始时间 开始时间

一生骄傲

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用自己的程序结束正在运行的其他程序。我现在用FindWindow函数来找到标题栏,以此<br>识辨另外的程序。可是我发现RealPlayer、QQ等软件在运行时标题栏会改变。RealPlayer会<br>加上播放文件的名字,而QQ的标题栏会变成QQ号码。请问我改怎么做?要达到的目的是不论<br>RealPlayer是播放什么、QQ是什么号码。我都能结束它们。谢谢
 
先用Spy++看一下主窗口的类名,然后FindWindow(类名,nil)<br>
 
我这里有案例是可以通过程序名来结束,需要吗
 
下面是去年计算机世界上的一段代码,功能是查找出所有的进程,如果点击按钮则会终止进<br>程,但是肯定可以满足你的要求:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,TLHelp32,<br>&nbsp; StdCtrls;<br><br>type<br><br>TProcessInfo=Record<br>&nbsp;ExeFile:String;<br>&nbsp;ProcessId:DWORD;<br>End;<br>&nbsp;ProcessInfo=^TProcessInfo;<br><br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure ProcessList(var PList:TList);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; Current:TList;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.ProcessList(var pList:TList);<br>&nbsp;var p:ProcessInfo;<br>&nbsp; &nbsp; ok:Bool;<br>&nbsp; &nbsp; ProcessListHandle:THandle;<br>&nbsp; &nbsp; ProcessStruct:TProcessEntry32;<br>Begin<br>&nbsp;PList:=TList.Create;<br>&nbsp;PList.Clear;<br>&nbsp;ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp;ProcessStruct.dwSize:=Sizeof(ProcessStruct);<br>&nbsp;ok:=Process32First(ProcessListHandle,ProcessStruct);<br>&nbsp;while Integer(ok)&lt;&gt;0 do Begin<br>&nbsp; new(p);<br>&nbsp; p.ExeFile:=ProcessStruct.szExeFile;<br>&nbsp; p.ProcessID:=ProcessStruct.th32ProcessID;<br>&nbsp; PList.Add(p);<br>&nbsp; ok:=Process32Next(ProcessListHandle,ProcessStruct);<br>&nbsp;End;<br>End;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>&nbsp;var i:Integer;<br>&nbsp; &nbsp;p:PRocessInfo;<br>begin<br>&nbsp;current:=TList.Create;<br>&nbsp;Current.Clear;<br>&nbsp;ListBox1.Clear;<br>&nbsp;ProcessList(Current);<br>&nbsp;for i:=0 to Current.Count-1 do Begin<br>&nbsp; new(p);<br>&nbsp; p:=Current.Items;<br>&nbsp; ListBox1.Items.Add(p.ExeFile);<br>&nbsp;End;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>&nbsp;var h:THandle;<br>&nbsp;a:DWORD;<br>&nbsp;p:PRocessInfo;<br>begin<br>&nbsp;if ListBox1.ItemIndex&gt;=0 then Begin<br>&nbsp; p:=Current.Items[ListBox1.ItemIndex];<br>&nbsp; h:=openProcess(Process_All_Access,true,p.ProcessID);<br>&nbsp; GetExitCodeProcess(h,a);<br>&nbsp; if Integer(TerminateProcess(h,a))&lt;&gt;0 then Begin<br>&nbsp; &nbsp;ListBox1.Clear;<br>&nbsp; &nbsp;FormCreate(Self);<br>&nbsp; End;<br>&nbsp;End; &nbsp;<br>end;<br><br>end.<br>
 
to:lanbing1400<br>&nbsp; 非常需要。可能的话发到我的信箱。wchcjg@sohu.com。我先谢了。
 
已经发过去了,请查收。<br><br>祝好运!
 
lanbing1400,<br>可以给我发送一份吗?在此谢过了<br>enterinto@sohu.com
 
to:hahali<br>&nbsp; 已经发送,请查收。<br>祝好运!
 
lanbing1400,<br>可以给我发送一份吗?在此谢过了<br>xiahongemail@yahoo.com.cn
 
to:夏雨天<br>&nbsp; 已经发送,请查收。<br>祝好运!<br>
 
解压有问题啊,大哥。能不能在发一次!谢谢
 
to:一生骄傲<br>&nbsp; 重新发过了!<br>&nbsp; 我这里试过,解压正常。如果还不行,你把文件复制到别人那里试一下吧。<br>&nbsp; 祝好运!
 
我也要<br>ty_unix@163.com
 
to:ty_unix<br>&nbsp; 已经发送,请查收。<br>祝好运!<br><br>
 
大哥还是不行啊。能不能把代码贴到上面,让我看看。谢谢!
 
to:lanbing1400<br>也请给我发一份看看。<br>toyzn2002@yahoo.com.cn<br>
 
多人接受答案了。
 
多人接受答案了。
 
后退
顶部