function GetModuleFileNameEx; external 'psapi.dll' name 'GetModuleFileNameExA';
function GetModuleFileNameFromWindow(hWnd: HWND): string; var Buffer: array[0..54] of Char; ProcessID: Cardinal; hProcess: Cardinal; begin Result := ''; if hWnd <> 0 then begin GetWindowThreadProcessId(hWnd, ProcessID); hProcess := OpenProcess(PROCESS_ALL_ACCESS, True, ProcessID); if hProcess <> 0 then begin GetModuleFileNameEx(hProcess, 0, @Buffer, 255); Result := Buffer; end; end; end;引用:http://topic.csdn.net/t/20050117/22/3733196.html
整理出来就是这样:
function GetModuleFileNameEx(hProcess: HINST; hModule: HINST; lpFilename: PChar;
nSize: DWORD): DWORD; stdcall;
function GetModuleFileNameEx; external 'psapi.dll' name 'GetModuleFileNameExA';
function GetModuleFileNameFromWindow(hWnd: HWND): string;
var
Buffer: array[0..54] of Char;
ProcessID: Cardinal;
hProcess: Cardinal;
begin
Result := '';
if hWnd <> 0 then
begin
GetWindowThreadProcessId(hWnd, ProcessID);
hProcess := OpenProcess(PROCESS_ALL_ACCESS, True, ProcessID);
if hProcess <> 0 then
begin
GetModuleFileNameEx(hProcess, 0, @Buffer, 255);
Result := Buffer;
end;
end;
end;引用:http://topic.csdn.net/t/20050117/22/3733196.html