Skip to content

Instantly share code, notes, and snippets.

@lniwn
Created February 8, 2017 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lniwn/09800663f848860df16bfb32f8e7ca62 to your computer and use it in GitHub Desktop.
Save lniwn/09800663f848860df16bfb32f8e7ca62 to your computer and use it in GitHub Desktop.
获取桌面进程窗口句柄
HWND WindowDeskPopUtils::GetDeskWindow()
{
HWND hSysView32 = NULL;
// 先按win7方式查找
HWND hWnd = NULL;
do
{
hSysView32 = ::FindWindowEx(NULL, hWnd, _T("Progman"), _T("Program Manager"));
if (hSysView32)
{
hSysView32 = GetSysView32(hSysView32);
if (hSysView32)
{
return hSysView32;
}
}
hWnd = hSysView32;
} while (hWnd);
// 再按Xp方式查找
hWnd = NULL;
do
{
hSysView32 = ::FindWindowEx(NULL, hWnd, _T("WorkerW"), NULL);
if (hSysView32)
{
hSysView32 = GetSysView32(hSysView32);
if (hSysView32)
{
return hSysView32;
}
}
hWnd = hSysView32;
} while (hWnd);
return NULL;
}
HWND WindowDeskPopUtils::GetSysView32(HWND hParent)
{
HWND hDeskWnd = NULL;
while (hParent)
{
HWND shellView = ::FindWindowEx(hParent, NULL, _T("SHELLDLL_DefView"), NULL);
if (shellView)
{
hDeskWnd = ::FindWindowEx(shellView, NULL, _T("SysListView32"), NULL);
break;
}
hParent = ::GetWindow(hParent, GW_HWNDNEXT);
}
return hDeskWnd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment