本文介绍了如何从进程ID中查找多个窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找和枚举与单个PID(进程ID)关联的所有窗口句柄,例如当程序使用单个进程中的多个窗口时。
我的尝试:
我发布了我认为这个问题的答案(为了Code Project社区的利益) )。请随意发布更好的答案。
How can one find and enumerate all window handles associated with a single PID (Process ID), for example when a program uses multiple windows from a single process.
What I have tried:
I published what I think to be the answer for this question (for the benefit of the Code Project community). Please feel free to publish better answers.
推荐答案
void GetAllWindowsFromProcessID(DWORD dwProcessID, std::vector <HWND> &vhWnds)
{
// find all hWnds (vhWnds) associated with a process id (dwProcessID)
HWND hCurWnd = NULL;
do
{
hCurWnd = FindWindowEx(NULL, hCurWnd, NULL, NULL);
DWORD dwProcessID = 0;
GetWindowThreadProcessId(hCurWnd, &dwProcessID);
if (dwProcessID == dwProcessID)
{
vhWnds.push_back(hCurWnd); // add the found hCurWnd to the vector
wprintf(L"Found hWnd %d\n", hCurWnd);
}
}
while (hCurWnd != NULL);
}
这篇关于如何从进程ID中查找多个窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!