【问题标题】:Is there a way to check which process is recieving User input?有没有办法检查哪个进程正在接收用户输入?
【发布时间】:2013-06-26 14:11:45
【问题描述】:

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

  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))

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

【问题讨论】:

  • GetForegroundWindow 将告诉您用户当前正在使用哪个窗口。您应该能够从返回的窗口句柄中获取进程。
  • 获取顶部窗口并检查它是否有焦点对话框?然后,如果为真,则获取与该窗口句柄关联的进程?
  • 如果可能的话,我想从进程中获取窗口,而不是从窗口中获取该进程。
  • 你需要通过窗口(GetWindowThreadProcessId)
  • @AlexK:非对话框可以拥有输入焦点。

标签: c++ multithreading winapi process


【解决方案1】:

GetForegroundWindow()GetWindowThreadProcessId() 是要走的路:

DWORD dwProcessID = 0;
HWND hFGWnd = GetForegroundWindow();
if (hFGWnd != NULL)
    GetWindowThreadProcessId(hFGWnd, &dwProcessID);
return dwProcessID;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-03
    • 2012-10-17
    • 1970-01-01
    • 2022-07-13
    • 1970-01-01
    • 2020-01-24
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多