Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Aug 28, 1999

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 Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal wCmd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal fEnable As Long) As Long

Private Const GW_CHILD = 5
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5

Sub 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 If
End Sub

Sub 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 If
End 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 Sub

Sub EnableDesktop(ByVal bEnable As Boolean)
    EnableWindow GetWindow( FindWindow("Progman", "Program Manager"), GW_CHILD), _
        bEnable
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date