1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| const S_MSG = 'Fenster: %d' + #13#10 + 'Titel: %s' + #13#10 + 'Dateiname: %s'; var AppHWnd: HWND; Title: String; ProcessId: DWORD; ProcessHandle: THandle; FileName: String; begin
AppHWnd := GetForegroundWindow;
if IsWindow(AppHWnd) then begin SetLength(Title, GetWindowTextLength(AppHWnd) + 1); SetLength(Title, GetWindowText(AppHWnd, PChar(Title), Length(Title)));
if GetWindowThreadProcessId(AppHWnd, ProcessId) <> 0 then if ProcessId <> 0 then begin ProcessHandle := OpenProcess(PROCESS_VM_READ or PROCESS_QUERY_INFORMATION, False, ProcessId); if ProcessHandle <> 0 then begin SetLength(FileName, MAX_PATH + 1); SetLength(FileName, GetModuleFileNameEx(ProcessHandle, 0, PChar(FileName), Length(FileName))); CloseHandle(ProcessHandle); end; end; end;
ShowMessage(Format(S_MSG, [AppHWnd, Title, FileName])); |