不常用的Windows API及小功能收集中...

来源:互联网 发布:highcharts 刷新数据 编辑:程序博客网 时间:2024/05/24 04:47

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;}




 




原创粉丝点击