Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Hide/show taskbar or desktop


Private Declare Function ShowWindow Lib "user32.dll <API_USER32.html>" ( ByVal hWnd As Long , ByVal nCmdShow As Long ) As Long
Private Declare Function FindWindow Lib "user32.dll <API_USER32.html>" Alias "FindWindowA" ( ByVal lpClassName As String , ByVal lpWindowName As String ) As Long
Private Declare Function EnableWindow Lib "user32.dll <API_USER32.html>" ( ByVal hWnd As Long , ByVal fEnable As Long ) As Long

Public Const SW_HIDE = 0
Public Const SW_SHOW = 5


Public Sub TaskBar(Visible As Boolean )
Dim hWnd As Long
hWnd = FindWindow( "Shell_TrayWnd" , "" )
If Visible Then
   ShowWindow hWnd, SW_SHOW
Else
   ShowWindow hWnd, SW_HIDE
End If
EnableWindow hWnd, Visible
End Sub

Public Sub Desktop(Visible As Boolean )
Dim hWnd As Long
hWnd = FindWindow( "Progman" , "Program Manager" )
If Visible Then
   ShowWindow hWnd, SW_SHOW
Else
   ShowWindow hWnd, SW_HIDE
End If
EnableWindow hWnd, Visible
End Sub


'-------------------------------
'alternate
Private Declare Function SetWindowPos Lib "user32" ( ByVal hwnd As Long , ByVal hWndInsertAfter As Long , ByVal x As Long , ByVal y As Long , ByVal cx As Long , ByVal cy As Long , ByVal wFlags As Long ) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String , ByVal lpWindowName As String ) As Long
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40


'Hide The TaskBar
Dim hwnd1 As Long
hwnd1 = FindWindow( "Shell_traywnd" , "" )
Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)

'Show The TaskBar
Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)


'=============================
'another
Just Call the ViewTaskBar subroutine And pass it True To show the taskbar Or False To hide it.

Option Explicit

Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_SHOWWINDOW = &H40

Private Declare Function FindWindow Lib _
                "user32" Alias "FindWindowA" _
               ( ByVal lpClassName As String , _
                ByVal lpWindowName As String ) As Long

Private Declare Function SetWindowPos Lib "user32" _
               ( ByVal hwnd As Long , _
                ByVal hWndInsertAfter As Long , _
                ByVal x As Long , ByVal y As Long , _
                ByVal cx As Long , ByVal cy As Long , _
                ByVal wFlags As Long ) As Long

Public Sub ViewTaskBar(lbValue As Boolean )
    Dim llResult As Long
   
   llResult = FindWindow( "Shell_traywnd" , "" )
   
    If llResult Then
        If lbValue Then
           llResult = SetWindowPos(llResult, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
        Else
           llResult = SetWindowPos(llResult, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
        End If
    End If
End Sub