Friday, February 13, 2009

[VC++] Programmatically Show/Hide Desktop contents

Below code snippet shows how to hide desktop content. Idea is simple find the Program Manager window and then get its child list view which host the desktop icons and hide it.

HWND hProgmMngrWnd, hDefViewWnd, hIconViewWnd;
hProgmMngrWnd = (FindWindow ("Progman", "Program Manager"))->GetSafeHwnd();
hDefViewWnd = FindWindowEx( hProgmMngrWnd, NULL, "SHELLDLL_DefView", NULL);
hIconViewWnd = FindWindowEx( hDefViewWnd, NULL, "SysListView32",NULL);
::ShowWindow( hIconViewWnd, SW_HIDE );

For programmaticaly showing the desktop icons replace the last line of the above code block with the below line of code(to show the window, instead of hiding).

::ShowWindow( hIconViewWnd, SW_SHOW );

No comments: