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):
