devxlogo

Hide or disable the desktop icons

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

See also  Redefining Energy Management: Advanced Solutions for Modern Buildings
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist