如何关闭其它程序'!??(100分)

  • 主题发起人 主题发起人 wein
  • 开始时间 开始时间
W

wein

Unregistered / Unconfirmed
GUEST, unregistred user!
如何关闭其它程序'!??<br><br>我知道要找到那个程序的句柄。像是用findwindow()吧。<br>然后再发一个WM_QUIT的消息,<br>但是不知道具体的的方法如何。<br>应该是不清楚具体的函数是那一个。<br>请能清楚地告诉我么?<br>具体的方法!<br>谢谢!
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Button3: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button3Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<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.Button1Click(Sender: TObject);<br>var<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>begin<br>&nbsp; &nbsp; &nbsp;// 初始化工作<br>&nbsp; &nbsp; &nbsp;FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; &nbsp; &nbsp;StartupInfo.cb := Sizeof(StartupInfo);<br><br>&nbsp; &nbsp; &nbsp;StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; &nbsp;CreateProcess(nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; 'Calc', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 运行计算器<br>&nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; false,<br>&nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW_CONSOLE or<br>&nbsp; &nbsp; &nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; StartupInfo,<br>&nbsp; &nbsp; &nbsp; &nbsp; ProcessInfo);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp;WinExec('NotePad',SW_RESTORE); &nbsp;// 运行写字本<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;HWndCalc: HWnd; &nbsp;// 窗口句柄<br>begin<br>&nbsp; &nbsp; &nbsp;// 查找“计算器”窗口<br>&nbsp; &nbsp; &nbsp;HWndCalc:= FindWindow(nil, '计算器');<br>&nbsp; &nbsp; &nbsp;if HWndCalc &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(HWndCalc, WM_CLOSE, 0, 0);<br>end;<br><br>end.<br>
 
如果遇到生命力顽强的程序,给它来一个TerminateProcess!<br>当然,要先找到它的ProcessID。
 
WM_CLOSE<br>WM_SYSCOMMAND, SC_CLOSE<br>WM_DESTROY
 
多人接受答案了。
 
后退
顶部