再delphi中怎样关闭外部的应用程序?谢谢(0分)

  • 主题发起人 主题发起人 hey777
  • 开始时间 开始时间
H

hey777

Unregistered / Unconfirmed
GUEST, unregistred user!
我是这样写的:<br>&nbsp; function ExecApplication(AppName: string): TExecuteResult;<br>var<br>&nbsp; hApp: HWND;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; hApp := WinExec(PChar(AppName), SW_SHOWNORMAL);<br>&nbsp; &nbsp; result := erSuccess;<br>&nbsp; except<br>&nbsp; &nbsp; result := erFailed;<br>&nbsp; end;<br>end;<br><br>procedure stopApplication(AppName: string);<br>var<br>&nbsp; a: integer;<br>&nbsp; hApp: HWND;<br>begin<br>&nbsp; hApp := FindWindow(nil, PChar(AppName));<br>&nbsp; a := -1;<br>&nbsp; if hApp &lt;&gt; 0 then<br>&nbsp; &nbsp; a := SendMessage(hApp, WM_CLOSE, 0, 0);<br>&nbsp; showmessage(inttostr(a));<br>end;<br><br>但在关闭应用程序时 hApp的返回值为0,这是为什么呢,谢谢:)
 
能不能用杀死进程来处理呢!<br><br>
 
楼主另一个帖子到哪儿去了?偶怎么找不到了?
 
请参阅此帖,有关文件的调用介绍的很详细<br>http://bbs.2ccc.com/topic.asp?topicid=48691
 
to Rainux:<br>http://www.delphibbs.com/delphibbs/dispq.asp?LID=2600296
 
妈的,又是零分帖!<br><br>procedure FindAProcess(const AFilename: string; const PathMatch: Boolean; var ProcessID: DWORD);<br>var<br>&nbsp; lppe: TProcessEntry32;<br>&nbsp; SsHandle: Thandle;<br>&nbsp; FoundAProc, FoundOK: boolean;<br>begin<br>&nbsp; ProcessID := 0;<br>&nbsp; lppe.dwSize := SizeOf(TProcessEntry32);<br>&nbsp; SsHandle := CreateToolHelp32SnapShot(TH32CS_SnapProcess, 0);<br>&nbsp; FoundAProc := Process32First(Sshandle, lppe);<br>&nbsp; if not FoundAProc then<br>&nbsp; &nbsp; ShowMessage(SysErrorMessage(GetLastError()));<br>&nbsp; while FoundAProc do<br>&nbsp; begin<br>&nbsp; &nbsp; if PathMatch then<br>&nbsp; &nbsp; &nbsp; FoundOK := AnsiStricomp(lppe.szExefile, PChar(AFilename)) = 0<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; FoundOK := AnsiStricomp(PChar(ExtractFilename(lppe.szExefile)), PChar(ExtractFilename(AFilename))) = 0;<br>&nbsp; &nbsp; if FoundOK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ProcessID := lppe.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FoundAProc := Process32Next(SsHandle, lppe);<br>&nbsp; end;<br>&nbsp; CloseHandle(SsHandle);<br>end;<br><br>function KillProcess(const AFileName:String;Const PathMatch:Boolean=False):Boolean;<br>var<br>&nbsp; PID:DWORD;<br>&nbsp; PHand:THandle;<br>begin<br>FindAProcess(AFileName,PathMatch,PID);<br>PHand:=OpenProcess(PROCESS_ALL_ACCESS,False,PID);<br>Result:=PHand&lt;&gt;0;<br>if Result then<br>&nbsp; Result:=TerminateProcess(PHand,0);<br>end;<br>
 
后退
顶部