Thank you for the great functions. I found a way to simplify the GetPath function and make it run significantly faster (~100 times). Here it is:
Code: Select all
F3::MsgBox % GetNotepadWinPath(WinExist("A"))
GetNotepadWinPath(hwnd) {
static MAX_PATH := 260
WinGetClass, Class, ahk_id %hwnd%
WinGet, PID, PID, ahk_id %hwnd%
hProc := DllCall("OpenProcess", "UInt", 0x410, "Int", 0, "UInt", PID, "Ptr") ; PROCESS_QUERY_INFORMATION (0x400) | PROCESS_VM_READ (0x010)
if !(Class = "Notepad" && hProc)
Return
DllCall("IsWow64Process", "Ptr", hProc, "IntP", IsWow64Process)
BaseAddress := DllCall(A_PtrSize = 4 ? "GetWindowLong" : "GetWindowLongPtr", "Ptr", hwnd, "Int", -6, "Ptr") ; GWLP_HINSTANCE = -6
Address := !A_Is64bitOS || IsWow64Process ? BaseAddress + 0xCAE0 : BaseAddress + 0x10B40
VarSetCapacity(Path, MAX_PATH*2, 0)
DllCall("ReadProcessMemory", "Ptr", hProc, "Ptr", Address, "Str", Path, "UPtr", MAX_PATH*2, "UPtr", 0)
DllCall("CloseHandle", "Ptr", hProc)
Return Path
}
- iPhilip
EDIT: Changed the function so that it now works with both Notepad x32 and x64 on Windows 7.