我正在尝试获取 SHELLDLL_DefView 的句柄。
所以,我有这个代码。
HWND hProgman = FindWindow(L"Progman", NULL);
HWND hWnd = FindWindowEx(hProgman, 0, L"SHELLDLL_DefView", NULL);
Eveyrtihing 工作正常,直到我将 Windows 桌面背景更改为幻灯片。然后,当我使用窗口的 spy++ 层次结构搜索时,SHELLDLL_DefView 有另一个父级。现在是#32769(桌面)-> WorkerW -> SHELLDLL_DefView。所以我找不到它。问题是当我尝试
HWND desktop = GetDesktopWindow();
HWND hWnd = FindWindowEx(desktop , 0, L"WorkerW", NULL);
HWND hWnd = FindWindowEx(hWnd, 0, L"SHELLDLL_DefView", NULL);
比 SHELLDLL_DefView 找不到。 worker W 是的。
有人可以帮忙吗?
最佳答案
您的代码仅适用于某些 Windows 版本,因为可以在“WorkerW”或“Progman”下找到“SHELLDLL_DefView”,并且您发现“WorkerW”类下可以有许多窗口(在 Win7 中正常)。
Microsoft Docs 报告 EnumWindows() 比在循环中调用 GetWindow()/FindWindowEx() 函数更可靠,因此更通用的代码(在 Windows 98/Windows 7 上测试)看起来像这样(假设你想刷新桌面):
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
HWND hNextWin;
hNextWin = FindWindowExA(hwnd, 0, "SHELLDLL_DefView", 0);
if ( hNextWin ) {
// The correct desktop shell window under Progman/WorkerW will have only 1 child window!
if ( GetNextWindow(hNextWin, GW_HWNDNEXT) || GetNextWindow(hNextWin, GW_HWNDPREV) )
return true;
// We found correct handle
PostMessageA(hNextWin, WM_KEYDOWN, VK_F5, 0);
return false;
}
return true;
}
void main() {
EnumWindows(&EnumWindowsProc, 0);
}
关于c++ - WinApi - 如何获取 SHELLDLL_DefView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36566675/