0

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

  • 1
    Actually you should open Desktop folder and enumerate files there. – user7860670 Apr 22 '18 at 09:06
  • Possible duplicate of [How do I get the window handle of the desktop?](https://stackoverflow.com/questions/1669111/how-do-i-get-the-window-handle-of-the-desktop) – fhe Apr 22 '18 at 09:07
  • It isn't a duplicate because this post doesn't help me. @VTT I want to get the icons count for hide icons later. –  Apr 22 '18 at 09:07
  • @VTT Icons come from virtual locations **and** two different filesystem folders. – Anders Apr 22 '18 at 09:40
  • @VTT Things like `Computer`, `Recycle Bin`, etc. show as icons but are not present in the folder – Killzone Kid Apr 22 '18 at 11:46
  • https://devblogs.microsoft.com/oldnewthing/20211122-00/?p=105948 There is an Old New Thing article on this question – pratikpc Dec 20 '21 at 17:14

1 Answers1

4

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.

Anders
  • 97,548
  • 12
  • 110
  • 164