Welcome to the fracta.net forum!

Share your coding ideas or ask questions.

Question Hide and show Windows task bar using Excel VBA and User32 dll

More
12 years 11 months ago #22 by roller
Let's say you want to hide Windows task bar for some reason, this is the bar at the bottom of your screen where all the running applications are displayed. To hide the task bar using VBA, get into the VBA editor by clicking ALT+F11 and create a new module. Use the code below, I will explain what each bit is for in the code comments.


'we need to use the Use32.dll Windows API to get the two required functions
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "User32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

'we declare our constants 0 hides and 5 shows
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5

'create a sub to get the tray window handle, if you pass 0 it will hide and reshow it if you pass 1
Sub ShowTskbr(ByVal bVisible As Boolean)
Dim hWnd_StartBar As Long
'this gets the windows handle for the tray
hWnd_StartBar = FindWindow("Shell_TrayWnd", "")
If bVisible Then
ShowWindow hWnd_StartBar, SW_SHOW
Else
ShowWindow hWnd_StartBar, SW_HIDE
End If
End Sub

'use this sub to call ShowTskbr, if you put 0 in the bracket the tray will disappear, put 1 to make it show
Sub main()
ShowTskbr (0)
End Sub

You can also use the code above to hide any running application. For example if you want to hide the Calculator use the code below. Make sure you declare the Windows User32 functions first.


Sub HideCalculator()
Dim hWnd_StartBar As Long
hWnd_StartBar = FindWindow("SciCalc", "Calculator")
ShowWindow hWnd_StartBar, SW_HIDE
End Sub


To hide any other application just get the windows handle by using FindWindow("class name", "application name") and pass it to the ShowWindow function.

Please Log in or Create an account to join the conversation.

Time to create page: 0.907 seconds
Powered by Kunena Forum