c++winapidesktop

Manipulating the positions of desktop icons


I am currently trying to retrieve the list of icons from my desktop to change their locations and / or hide them as well as display others.

I tried to get the FolderView in the code below but it doesn't even show the number of icons I have on the desktop because count return 0.

HWND hDesktop = GetDesktopWindow();
HWND hDefView = FindWindowEx(hDesktop, NULL, L"SHELLDLL_DefView", NULL);
HWND folderView = FindWindowEx(hShellWnd, NULL, L"SysListView32", NULL);

int count = (int) SendMessage(folderView, LVM_GETITEMCOUNT, 0, 0);
cout << count << endl;

I did tests on the variables and is noticed that hDefView is NULL.
Probably the reason why count return 0.

EDIT : After replace GetDesktopWindow by GetShellWindow the result is always the same, 0


Solution

  • The shell window hierarchy is not documented nor stable. "ProgMan" is usually the parent of "SHELLDLL_DefView" but if you change to slideshow wallpaper it can also be "WorkerW".

    It is much better to inspect/manipulate the desktop with the documented shell COM interfaces: IShellWindows, IShellBrowser, IFolderView and IShellFolder.