WinApi - How to obtain SHELLDLL_DefView

前端 未结 2 1388
感动是毒
感动是毒 2021-01-25 07:18

I am trying to obtain handle to SHELLDLL_DefView.

So, I have this code.

HWND hProgman = FindWindow(L\"Progman\", NULL);
HWND hWnd = FindWindowEx(hProgman         


        
相关标签:
2条回答
  • 2021-01-25 07:25

    Your code only works on some Windows versions as "SHELLDLL_DefView" can be found under "WorkerW" or "Progman" and as you discovered there can be many windows under the "WorkerW" class (normal in Win7).

    Microsoft Docs report EnumWindows() is more reliable than calling GetWindow()/FindWindowEx() functions in loops, so more universal code (tested on Windows 98/Windows 7) would look like this (say you want to refresh the desktop):

    BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
        HWND hNextWin;
        hNextWin = FindWindowExA(hwnd, 0, "SHELLDLL_DefView", 0);
        if ( hNextWin ) {
        // The correct desktop shell window under Progman/WorkerW will have only 1 child window!
            if ( GetNextWindow(hNextWin, GW_HWNDNEXT) || GetNextWindow(hNextWin, GW_HWNDPREV) )
                return true;
        // We found correct handle
            PostMessageA(hNextWin, WM_KEYDOWN, VK_F5, 0);
            return false;
        }
        return true;
    }
    
    void main() {
       EnumWindows(&EnumWindowsProc, 0);
    }
    
    0 讨论(0)
  • 2021-01-25 07:32

    I found the answer. Need to iterate through all WorkerW.

    HWND destop = GetDesktopWindow();
    HWND hWorkerW = NULL;
    HWND hShellViewWin = NULL;
    do
    {
        hWorkerW = FindWindowEx(destop, hWorkerW, L"WorkerW", NULL);
        hShellViewWin = FindWindowEx(hWorkerW, 0, L"SHELLDLL_DefView", 0);
    } while (hShellViewWin == NULL && hWorkerW != NULL);
    
    0 讨论(0)
提交回复
热议问题