Windows Desktop ListView Handle
I have been using a utility function in my TaskbarExt application for years to get the current Desktop ListView window handle (SysListView32 to be exact) to show/hide the icons depending on user preferences.
This has worked well for years, but recently I enabled the Windows Desktop wallpaper rotation, and I noticed that this function randomly stops working. On debugging the issue, I found that when the wallpaper rotation is enabled, instead of loading the “SHELLDLL_DefView” window in the “Progman”, Windows was loading under the “WorkerW” window. BTW, the Spy++ Tool was great help in debugging all this.
Once I know what’s going on, the fix was quite easy. In case your are running into similar issues, here is the sample code which works for me:
HWND GetDesktopListViewHWND()
{
HWND hDesktopListView = NULL;
HWND hWorkerW = NULL;
HWND hProgman = FindWindow(_T("Progman"), 0);
HWND hDesktopWnd = GetDesktopWindow();
// If the main Program Manager window is found
if (hProgman)
{
// Get and load the main List view window containing the icons (found using Spy++).
HWND hShellViewWin = FindWindowEx(hProgman, 0, _T("SHELLDLL_DefView"), 0);
if (hShellViewWin)
hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0);
else
// When this fails (happens in Windows-7 when picture rotation is turned ON), then look for the WorkerW windows list to get the
// correct desktop list handle.
// As there can be multiple WorkerW windows, so iterate through all to get the correct one
do
{
hWorkerW = FindWindowEx( hDesktopWnd, hWorkerW, _T("WorkerW"), NULL );
hShellViewWin = FindWindowEx(hWorkerW, 0, _T("SHELLDLL_DefView"), 0);
} while (hShellViewWin == NULL && hWorkerW != NULL);
// Get the ListView control
hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0);
}
return hDesktopListView;
}
Hopefully the comments should explain what’s going on very well. But if you still have any questions or suggestions, please do share with me.
On a side note, any wallpaper with icons turned off looks so beautiful. So I would recommend give this a try. So, if you are a programmer, which you most probably are if are reading so far, then better go ahead and implement this yourself. It will be a nice little utility. If however, busy with some other stuff, you can try my TaskbarExt application and get this in action quickly.
Tags: Desktop, Handle, Win32 API, Window
This entry was posted
on Saturday, January 19th, 2013 at 2:39 pm and is filed under Visual C++, Win32 API.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Good!!
Thank you!!
Great – works well, I spent hours trying to work this out, is nobody else developing this stuff on Windows 7.
Thankyou very much ………………….
i spent time for this so much.
Thankyou.