I have an application that helps people with disabilities. For work, it keeps track of which window is in the foreground. I usually use this function to get the process executable.
bool GetWindowProcessExe2(HWND hwnd, wxString& process_exe)
{
DWORD result = 0;
DWORD pid = 0;
GetWindowThreadProcessId(hwnd, &pid);
if (HANDLE process =
OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid))
{
char buff[512];
LPTSTR pbuff = buff;
result = GetModuleFileNameEx(process, 0, pbuff, 512);
if(result == 0)
{
wxLogError("GetModuleFileNameEx failed with error code %d", GetLastError());
}
CloseHandle(process);
process_exe = fromCString(pbuff);
}
return result > 0 ? true : false;
}
, Vista (, "" > "" ), GetModuleFileNameEx() 299, , . , , ( ). , . ? , . ?