Hide or disable the desktop icons

The Desktop is a window like any other window in the system, so you can hide/show and enable/disable it. The only details you need to know is how to retrieve the handle to the Desktop window. It turns out that this window is the first child window of the “Program Manager” window, so all you need is a couple of API functions:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _    lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _    ByVal wCmd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _    ByVal nCmdShow As Long) As LongPrivate Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, _    ByVal fEnable As Long) As LongPrivate Const GW_CHILD = 5Private Const SW_HIDE = 0Private Const SW_SHOW = 5Sub ShowDesktopIcons(ByVal bVisible As Boolean)    Dim hWnd_DesktopIcons As Long    hWnd_DesktopIcons = GetWindow( FindWindow("Progman", "Program Manager"), _        GW_CHILD)    If bVisible Then        ShowWindow hWnd_DesktopIcons, SW_SHOW    Else        ShowWindow hWnd_DesktopIcons, SW_HIDE    End IfEnd SubSub EnableDesktop(ByVal bEnable As Boolean)    Dim hWnd_Desktop As Long    hWnd_Desktop = GetWindow( FindWindow("Progman", "Program Manager"), _        GW_CHILD)    If bEnable Then        EnableWindow hWnd_Desktop, True    Else        EnableWindow hWnd_Desktop, False    End IfEnd Sub

You can make the above code more concise in this way:

Sub ShowDesktopIcons(ByVal bVisible As Boolean)    ShowWindow GetWindow( FindWindow("Progman", "Program Manager"), GW_CHILD), _        IIf(bVisible, SW_SHOW, SW_HIDE)End SubSub EnableDesktop(ByVal bEnable As Boolean)    EnableWindow GetWindow( FindWindow("Progman", "Program Manager"), GW_CHILD), _        bEnableEnd Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS