Created
February 8, 2017 07:22
-
-
Save lniwn/09800663f848860df16bfb32f8e7ca62 to your computer and use it in GitHub Desktop.
获取桌面进程窗口句柄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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