源代码:
-------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
p rivate
{ P rivate declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses PsAPI;
procedure TForm1.Button1Click(Sender: TObject);
begin
if FindWindow('Notepad',nil)=0 then
WinExec('notepad.exe',SW_SHOW);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
hwnd1:HWND;
h:Cardinal;
ph1:Cardinal;
pathName:string;
begin
hwnd1:=FindWindow(PChar(Edit1.Text),nil); //取窗体句柄
GetWindowThreadProcessId(hwnd1,@h); //取窗体创建者线程或进程的PID
ph1:=OpenProcess( PROCESS_ALL_ACCESS,False,h);//由PID取得进程句柄
SetLength(pathName,MAX_PATH);
//由进程句柄取得模块全路径
GetModuleFileNameEx(ph1,0,PChar(pathName),MAX_PATH);
//GetModuleFileName(0,PChar(pathName),MAX_PATH);
Memo1.Clear;
memo1.Lines.Add(pathName);
end;
end.
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.040295124053955 seconds