WIN10获取桌面窗口句柄
1 HWND GetDesktopHandle() 2 { 3 HWND hwndTopWindow = nullptr; 4 HWND hwndShellDefView = nullptr; 5 HWND hwndDesktop = nullptr; 6 while (hwndDesktop == nullptr) 7 { 8 hwndTopWindow = FindWindowExW(nullptr, hwndTopWindow, L"WorkerW", nullptr); 9 if (hwndTopWindow == nullptr) 10 hwndTopWindow = FindWindowExW(nullptr, hwndTopWindow, L"Progman", L"Program Manager"); 11 hwndShellDefView = FindWindowExW(hwndTopWindow, nullptr, L"SHELLDLL_DefView", nullptr); 12 if (hwndShellDefView == nullptr) 13 continue; 14 hwndDesktop = FindWindowExW(hwndShellDefView, nullptr, L"SysListView32", nullptr); 15 } 16 return hwndDesktop; 17 }