API小问题(100分)

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

wz_hzb

Unregistered / Unconfirmed
GUEST, unregistred user!
已获得一个窗口的句柄,如何获得该窗口所在程序的目录?
 
get windows process id<br>enumprocess
 
能不能具体点?谢谢!<br>
 
用如下代码就可以啦:方法也是用enumprocess<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; Memo1: TMemo;<br>&nbsp; &nbsp; procedure Button1Click(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>function EnumWindowsProc(AHWnd: HWnd;<br>&nbsp; LPARAM: lParam): boolean; stdcall;<br>var<br>&nbsp; WndCaption: array[0..254] of char;<br>&nbsp; WndClassName: array[0..254] of char;<br>begin<br>&nbsp; GetWindowText(AHWnd, @WndCaption, 254);<br>&nbsp; GetClassName(AHWnd, @WndClassName, 254);<br>&nbsp; with Form1.Memo1.Lines do<br>&nbsp; begin<br>&nbsp; &nbsp; Add(StrPas(WndCaption));<br>&nbsp; &nbsp; Add(StrPas(WndClassName));<br>&nbsp; &nbsp; Add('-------');<br>&nbsp; end;<br><br>&nbsp; Result := True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Memo1.Lines.Clear;<br>&nbsp; EnumWindows(@EnumWindowsProc, 0);<br>end;<br><br>end.<br><br>
 
以上得不到路径吧!只能得到类名和标题。
 
关注,我只能编程得到程序名,得不到路径。
 
在form上放一个memo和button,在button的onclick事件中写如下代码:<br>var<br>&nbsp; lppe:TProcessEntry32;<br>&nbsp; SsHandle:Thandle;<br>&nbsp; FoundAProc, FoundOK:boolean;<br>begin<br>&nbsp; SsHandle &nbsp; := CreateToolHelp32SnapShot(TH32CS_SNAPALL,0);<br>&nbsp; lppe.dwSize:=sizeof(TProcessEntry32);<br>&nbsp; FoundAProc := Process32First(Sshandle,lppe);<br>&nbsp; while FoundAProc do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Memo1.add(lppe.szExefile);<br>&nbsp; &nbsp; &nbsp; FoundAProc :=Process32Next(SsHandle,lppe);<br>&nbsp; end;<br>&nbsp; if not FoundAProc then<br>&nbsp; &nbsp; Memo1.Add(SysErrorMessage(GetLastError));<br>&nbsp; CloseHandle(SsHandle);<br>end;
 
接受答案了.
 
后退
顶部