1. 判断当前OS默认的是单击还是双击
BOOL IsDoubleClickInWebView()
{
SHELLFLAGSTATE sfs;
ZeroMemory(&sfs, sizeof(SHELLFLAGSTATE));
SHGetSettings(&sfs, SSF_DOUBLECLICKINWEBVIEW);
return sfs.fDoubleClickInWebView != 0 ? TRUE : FALSE;
}
2. 获取当前桌面的窗口句柄
HWND FindShellWindow()
{
// Sometimes, we can't find the desktop window when we use this function, but we must
// find it's handle, so we do a loop to find it, but at most we find for 10 times.
UINT uFindCount = 0;
HWND hSysListView32Wnd = NULL;
while (NULL == hSysListView32Wnd && uFindCount < 10)
{
HWND hParentWnd = ::GetShellWindow();
HWND hSHELLDLL_DefViewWnd = ::FindWindowEx(hParentWnd, NULL, L"SHELLDLL_DefView", NULL);
hSysListView32Wnd = ::FindWindowEx(hSHELLDLL_DefViewWnd, NULL, L"SysListView32", L"FolderView");
if (NULL == hSysListView32Wnd)
{
hParentWnd = ::FindWindowEx(NULL, NULL, L"WorkerW", L"");
while((!hSHELLDLL_DefViewWnd) && hParentWnd)
{
hSHELLDLL_DefViewWnd = ::FindWindowEx(hParentWnd, NULL, L"SHELLDLL_DefView", NULL);
hParentWnd = FindWindowEx(NULL, hParentWnd, L"WorkerW", L"");
}
hSysListView32Wnd = ::FindWindowEx(hSHELLDLL_DefViewWnd, 0, L"SysListView32", L"FolderView");
}
if (NULL == hSysListView32Wnd)
{
Sleep(1000);
uFindCount++;
}
else
{
break;
}
}
return hSysListView32Wnd;
}