Doubts about the window of "program manager"

Rer 80 Reputation points
2023-10-09T14:53:11.8033333+00:00

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_DESTROY:
            SetParent(hProgman, NULL);
            UpdateWindow(hProgman);
            UpdateWindow(hDefView);
            UpdateWindow(hSysListView);
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(...)
{
	...
    HWND hDesktop = GetDesktopWindow();
    hProgman = FindWindow(TEXT("Progman"), TEXT("Program Manager"));

    hDefView = FindWindowEx(hProgman, NULL, TEXT("SHELLDLL_DefView"), NULL);
    
    // HWND hWorkerW = NULL;
    // HWND hDefView = NULL;
    // while(!hDefView)
    // {
        // hWorkerW = FindWindowEx(NULL, hWorker, TEXT("WorkerW"), NULL); //Find next WorkerW
        // hDefView = FindWindowEx(hWorkerW, NULL, TEXT("SHELLDLL_DefView"), NULL);
    // }
    hSysListView = FindWindowEx(hDefView, NULL, TEXT("SysListView32"), TEXT("FolderView"));
    cout << hProgman << " " << hDefView << " " << hSysListView << " " << hDesktop << endl;

    SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE));
    SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, width, height, SWP_FRAMECHANGED);


    UpdateWindow(hwnd);
    SetParent(hSysListView, hSysListView);
    SetWindowLongPtr(hSysListView, GWL_EXSTYLE, GetWindowLongPtr(hSysListView, GWL_EXSTYLE) ^ WS_CHILD);
    SetParent(hDefView, hwnd);
    UpdateWindow(hwnd);
    UpdateWindow(hDefView);
    UpdateWindow(hSysListView);
	...
}

(Part of code ↑)

I try to set a window of mine to be the parent window of program manager so that I can dynamically draw something under icon layer. But when I set program manager to non-parent before quit the window (not sure whether it works), the desktop with icons disapear with my window. Spy++ shows this (before running my program, the Program Manager had a child window DefView, but it is gone now):

屏幕截图 2023-10-09 224340

Windows development Windows API - Win32
Developer technologies C++
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2023-10-09T18:07:47.8633333+00:00

    I try to set a window of mine to be the parent window of program manager so that I can dynamically draw something under icon layer.

    It is the reverse, you must set your window as child, not of Progman, but of "WorkerW" window, as explained in CodeProject article

    See for example create_worker_window function at https://github.com/MathiasPius/LOVEGROUND/blob/master/main.cpp

    Then if you test with a hWnd :

    HWND hWndWorker = create_worker_window();
    SetParent(hWnd, hWndWorker);
    

    It will be displayed on Desktop, behind icons

    (then you can draw anything in your hWnd, or launching videos, ...)

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.