1

有没有办法从所有正在运行的进程的完整列表中检查哪个进程正在接收用户输入?例如:

  PROCESSENTRY32 procentry;
HANDLE hproc;
BOOL retval, ProcFound = false;

hproc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //GetsSnapshotOfAllProcesses
if(hproc == INVALID_HANDLE_VALUE)
{ // If Couldnt get snapshot 
   MessageBox(NULL, "Unable To Get Snapshot", "LoaderError", MB_OK);
   return false;
}
procentry.dwSize = sizeof(PROCESSENTRY32); // Initialize
retval = Process32First(hproc, &procentry); //Copies Snapshot procentry

while(retval)
{
    **if(UserInput == TRUE))**
    {
    return procentry.th32ProcessID; //
    }
    retval = Process32Next(hproc, &procentry); // 
}
return 0;

}

是否有一个功能可以让我检查哪个进程正在接收用户输入?

if(UserInput == TRUE))

另外,有没有办法将流程转换为字符串?

4

1 回答 1

2

GetForegroundWindow() and GetWindowThreadProcessId() is the way to go:

DWORD dwProcessID = 0;
HWND hFGWnd = GetForegroundWindow();
if (hFGWnd != NULL)
    GetWindowThreadProcessId(hFGWnd, &dwProcessID);
return dwProcessID;
于 2013-06-26T19:43:47.027 回答