• 0

C++/Windows 7: Can't programmatically "hide" desktop icons


Question

I've been using C++ to send an LVM_DELETEITEM message to the desktop listview window, but it seems to be ignoring the index I give it.

It always seems to delete the same icon (last index), regardless of whichever index I send as the WPARAM.

I've tried using both Listview_DeleteItem() and SendMessage(LVM_DELETEITEM).

It seems Microsoft has subclassed the listview and are handling the LVM_DELETEITEM message differently to previous versions of Windows.

The code has been tested and working fine with WinXP x86, Vista (x86 and x64).

Both Win7 x86 and x64 are showing this strange behaviour.

Does anyone know of another way I can get this to work?

Any suggestions are welcome!

9 answers to this question

Recommended Posts

  • 0

This is a very flaky thing to be doing, and it shouldn't be surprising that it no longer works.

First, LVM_DELETEITEM was never designed to be sent directly by an external source (e.g., it's not like WM_KEYDOWN, which can be sent as the result of user input, and it's not designed to be sent by external apps). LVM_DELETEITEM is really more like an API, to allow the application that uses the list view control to communicate with the list view control, and since the list view control is implemented as a window, the API takes the form of window messages. Just because window messages can be sent by an external application doesn't mean that it should be sent, and this is one example of that. By injecting yourself into the private interactions of Explorer and its list view control, you may very well violate assumptions that Explorer may make about the state of the list view.

This is especially true for Explorer's main list view, since that list view is almost certainly a virtual list view, in which Explorer maintains much of the list view's state. Sending LVM_DELETEITEM from an external app in a situation like this is simply a bad idea, and it's surprising that this hack has even worked at all up to this point.

If you want to hide a file, why not just call SetFileAttributes and flip on the hidden bit?

(PS: Listview_DeleteItem is just a C macro that expands out to SendMessage LVM_DELETEITEM)

  • 0
  code.kliu.org said:
Sending LVM_DELETEITEM from an external app in a situation like this is simply a bad idea, and it's surprising that this hack has even worked at all up to this point.

If you want to hide a file, why not just call SetFileAttributes and flip on the hidden bit?

yes, i know its a bad idea and im not happy that i have to do this at all.

but ever since vista, the desktop has decided to simply ignore the hidden attribute on desktop.ini files

i'm just trying to make something that'll hide the icons without the need to delete the files.

  • 0
  twigboy said:
but ever since vista, the desktop has decided to simply ignore the hidden attribute on desktop.ini files

That's not Explorer's fault. Nor Vista's. It's simply doing what you are telling it to do. It still honors the hidden attribute. And the system attribute. desktop.ini has both +H and +S set. The desktop will only show desktop.ini if you enable "Show hidden files and folders" (which shows files with the +H bit) and uncheck "Hide protected operating system files" (which shows files with the +S bit). If you enable both of those options, then Explorer, by design, should show desktop.ini. If either one of those is not set, then desktop.ini will be hidden.

Incidentally, the reason why desktop.ini has the +S bit set is so that people can turn on "Show hidden files" and not have to see desktop.ini (aside from desktop.ini, very few files actually use the +S bit).

XP didn't have a desktop.ini for the Desktop folder, which is why you didn't see this in XP. But if you created a desktop.ini in XP, set the +H and +S attribs on it, but then enable the options to show +H and +S in Explorer, you'll see desktop.ini on your desktop, just like in Vista.

Now, if you insist on keeping both the "show +H" and "show +S" options enabled in Explorer, and you are bothered by the desktop.ini files, you can just delete them. It's only there so that it can show a special cute icon for the folder and use a localized display name, but if you care about neither of those things, you can just delete desktop.ini.

Edited by code.kliu.org
  • 0
  code.kliu.org said:
Now, if you insist on keeping both the "show +H" and "show +S" options enabled in Explorer, and you are bothered by the desktop.ini files, you can just delete them. It's only there so that it can show a special cute icon for the folder and use a localized display name, but if you care about neither of those things, you can just delete desktop.ini.

well yes, i do like having an icon for my desktop which is why i do not want to opt for the brute "delete the file" method.

  • 0
  code.kliu.org said:
This is especially true for Explorer's main list view, since that list view is almost certainly a virtual list view, in which Explorer maintains much of the list view's state. Sending LVM_DELETEITEM from an external app in a situation like this is simply a bad idea, and it's surprising that this hack has even worked at all up to this point.

If he insists on using the LVM_DELETEITEM method, wouldn't it be possible instead to inject a custom DLL into explorer, and send the LVM_DELETEITEM message through the injected process? If the reason being that explorer now ignores the LVM_DELETEITEM message from external apps it should work right? Not saying that this is a good idea either though. Just an interesting thought.

  • 0
  dlegend said:
... wouldn't it be possible instead to inject a custom DLL into explorer, and send the LVM_DELETEITEM message through the injected process?

yep, thats what i'm currently doing

i've subclassed it to make sure that the right message is being passed through and its correct up until the point where i have to process the LVM_DELETEITEM message

im wondering if theres a way to temporarily replace the custom LVM_DELETEITEM handler for the desktop with the default SysListview wndproc.

suggestions/advice still welcome!

  • 0
  dlegend said:
If he insists on using the LVM_DELETEITEM method, wouldn't it be possible instead to inject a custom DLL into explorer, and send the LVM_DELETEITEM message through the injected process?

That's not the problem. Whether the message comes from the Explorer process or not is irrelevant. The interaction between the list view and Explorer is just that: between the list view and Explorer, especially since the W7 list view is a virtual list view and Explorer is maintaining much of the list view state. It doesn't matter how you inject yourself into this.

If you are typing on your keyboard and your cat decides that it likes to walk on the keyboard, it's going to be disruptive regardless of whether your cat walks on the same keyboard that you are currently typing on or on a second keyboard connected to the same computer.

  twigboy said:
im wondering if theres a way to temporarily replace the custom LVM_DELETEITEM handler for the desktop with the default SysListview wndproc.

You can't--and most importantly, shouldn't--do this with LVM_DELETEITEM. Period. Nor would subclassing or "replacing" LVM_DELETEITEM work since this is a virtual list view where the list view itself does not maintain the state.

  twigboy said:
suggestions/advice still welcome!

If you really insist on showing +S files and having a cute icon for your desktop and hiding desktop.ini, then you have two options:

Option 1: Create a custom shell extension implementing the IExtractIcon interface that sets a cute, pretty icon for the desktop folder (thus bypassing the need for desktop.ini) and then delete desktop.ini.

Option 2: Get the IShellFolderView interface (hint) for the desktop shell view, find the desktop.ini object, and call IShellFolderView::RemoveObject on it.

Seems like a lot of effort to go through for a cute icon. :p

Disclaimer: I haven't actually tried either option. In theory, they should work, but as you can imagine, this isn't something that many people have tried doing before.

Edited by code.kliu.org
  • 0
  code.kliu.org said:
Option 2: Get the IShellFolderView interface (hint) for the desktop shell view, find the desktop.ini object, and call IShellFolderView::RemoveObject on it.

Seems like a lot of effort to go through for a cute icon. :p

thanks for that, i'll try it out and let you guys know how it goes.

i dont really mind the trouble. despite being much more difficult than deleting the files, its a good excuse to learn some new tricks :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft removes PowerShell 2.0 from Windows 11 in build 27891 by Taras Buria Microsoft has released a new Windows 11 preview build from the Canary Channel. Build 27891 is out with several improvements and fixes, a new feature for the Microsoft Store, and the removal of PowerShell 2.0, which is now deprecated. Microsoft deprecated PowerShell 2.0 all the way back in Windows 10 version 1709. Last month, it issued a reminder about it, and now, PowerShell 2.0 is gone from the latest Windows 11 Canary builds. Microsoft says it will publish more information about PowerShell 2.0 removal in the upcoming update for Windows 11. Also, Microsoft is rolling out a new update for the Microsoft Store. Version 22406 is rolling out to Windows Insiders in the Canary and Dev Channels, offering the ability to install a product right from the Store's home page, as seen in the screenshot below: Here is what was fixed: [General] We fixed the issue causing the “Reset this PC” option under Settings > System > Recovery to not work after upgrading the last few Canary Channel builds. Fixed the underlying issue which was causing the taskbar to unexpectedly not showing acrylic material after upgrading to the latest Canary builds. This also impacted a few other scenarios, leading to unexpected black or white in some UI. Fixed an underlying issue believed to be the cause of some Insiders seeing Windows update downloads to get stuck at 2% recently. Fixed a few more languages including Vietnamese and Arabic that were still having issues with certain characters not rendering correctly for Insiders after the latest builds, causing nonsense to display in places like Task Manager and more. This impacted characters outside of A-Z. [File Explorer] Fixed an issue where if you opened the “…” menu in the File Explorer address bar to show the full list of folders for the current path, the dropdown might be cut off and the bottom of it inaccessible. [Settings] Fixed an issue in the previous build which could cause Settings to crash when opening microphone properties under Settings > System > Sound. Fixed an underlying issue related to Bluetooth which could cause Settings or Quick Settings to crash on launch for some people. [Windowing] Fixed an issue which was causing the window minimizing animation to not display correctly in the previous flight. [Task Manager] Fixed an issue where the CPU graphs in the Performance page were still using the old CPU utility calculations. Fixed an issue where after adding the new CPU Utility column, you might notice that System Idle Process always showed as 0. [Audio] Fixed an issue which could cause all system sounds to stop working (for example notification alert sound and the sound that plays when clicking the volume slider in quick settings), although audio in general was working on your PC. [Other] Fixed an underlying issue which was causing fonts in certain app menu items to unexpectedly appear corrupted or overlapped for some people. This also impacted typing in Word – where when using Hebrew a period may unexpectedly show as a 3, and in Thai typing space may show a 2. Fixed an underlying issue which could cause the playback controls in Media Player to become distorted in the latest Canary flights. Fixed an underlying issue believed to be the cause of LDAP queries from apps to take an unexpectedly long time in the previous flight. Fixed an issue which could cause print previews to appear slightly blurry in recent Canary flights. Here is the list of known issues: [General] [IMPORTANT NOTE FOR COPILOT+ PCs] If you are joining the Canary Channel on a new Copilot+ PC from the Dev Channel, Release Preview Channel or retail, you will lose Windows Hello pin and biometrics to sign into your PC with error 0xd0000225 and error message “Something went wrong, and your PIN isn’t available”. You should be able to re-create your PIN by clicking “Set up my PIN”. [Settings] [NEW] We’re investigating an issue in this build which could cause Settings to crash when interacting with the options under Settings > System > Power & Battery. [Remote Desktop] [NEW] You may see extreme graphical distortion and rendering issues using remote desktop on Arm64 PCs in this build. You can find full release notes for build 27891 in a post on the official Windows Blogs website.
    • Sounds like corporate spamming being painted as a "feature"...so long as it can be blocked like any other random creep messaging you, no biggie.
    • Don't really like these kinds of games but that song is nice.
    • SVE: easy video editor for trimming and cropping by Razvan Serea SVE SimpleVideoEditor is a lightweight, open-source video editor designed with simplicity and speed in mind. Built using Python and featuring a clean graphical user interface, it allows users to perform essential video editing tasks without the complexity of professional software. The tool supports trimming clips, cropping video frames, and extracting audio from video files, making it perfect for quick edits and basic media tasks. Its intuitive design ensures that even beginners can navigate and use it effectively without a steep learning curve. SVE SimpleVideoEditor doesn’t require heavy system resources or complicated installation steps, making it accessible on a wide range of systems. Ideal for casual users or anyone looking for a minimal yet functional editing tool, it offers a straightforward experience focused on getting the job done with minimal hassle. While more advanced tools like Shotcut offer extensive editing features and LosslessCut excels in ultra-fast, lossless trimming, SVE stands out for its simplicity and ease of use. Download: SimpleVideoEditor v2025.06.29 | 87.7 MB (Open Source) Links: SimpleVideoEditor Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Devesh Beri earned a badge
      Week One Done
    • Week One Done
      956400 earned a badge
      Week One Done
    • First Post
      loose_observer earned a badge
      First Post
    • Week One Done
      BeeJay_Balu earned a badge
      Week One Done
    • Week One Done
      filminutz earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      470
    2. 2
      ATLien_0
      159
    3. 3
      +FloatingFatMan
      151
    4. 4
      Nick H.
      66
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!