A few days ago, a student asked me whether or not it is possible to manipulate the TaskBar from within a VB.NET program, so I decided to create this sample application for her. With this article, I will show you how to create an application that can set and apply most taskbar settings. Features include:
- Lock the TaskBar
- AutoHide the TaskBar
- Keep TaskBar on top
- Group similar TaskBar buttons
- Hide TaskBar contents, in other words the active window buttons
- Hide the clock
- Disable the Start button
- Auto Hide Inactive Tray icons
- Change Start button text
- Show Desktop feature
- Show TaskBar properties
Design
I have designed my form as shown in Figure 1. Feel free to give your buttons your own descriptive names.
Figure 1: The Design
Coding
Add the following Import on top of your code window because it will use some Registry functions throughout this article:
Imports Microsoft.win32 'Registry Functions Imports System.Runtime.InteropServices 'API functions
To avoid confusion and possible ambiguities, I have decided to start with all the APIs and their associated constants. Now, add them to your code window:
'Find External Window Private Declare Function FindWindow Lib "user32.dll" Alias _ "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Int32 'Find Child Window Of External Window Private Declare Function FindWindowEx Lib "user32.dll" Alias _ "FindWindowExA" (ByVal hWnd1 As Int32, _ ByVal hWnd2 As Int32, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Int32 'Show A Window Private Declare Function ShowWindow Lib "user32.dll" _ (ByVal hwnd As Int32, _ ByVal nCmdShow As Int32) As Int32 'Post Message To Window Private Declare Function PostMessage Lib "user32.dll" Alias _ "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As Int32) As Int32 'Enable A Window Private Declare Function EnableWindow Lib "user32.dll" _ (ByVal hwnd As Int32, ByVal fEnable As Int32) As Int32 'SendMessage lParam = String Private Declare Function SendMessageSTRING Lib _ "user32.dll" Alias "SendMessageA" _ (ByVal hwnd As Int32, _ ByVal wMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As String) As Int32 'Send Message & Wait Declare Auto Function SendMessageTimeout Lib "User32" ( _ ByVal hWnd As Integer, _ ByVal Msg As UInt32, _ ByVal wParam As Integer, _ ByVal lParam As Integer, _ ByVal fuFlags As UInt32, _ ByVal uTimeout As UInt32, _ ByRef lpdwResult As IntPtr _ ) As Long 'Normal SendMessage Private Declare Function SendMessage Lib "user32.dll" _ Alias "SendMessageA" _ (ByVal hwnd As Int32, _ ByVal wMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As Int32) As Int32 'Get Handle To Desktop Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr Private Const WM_WININICHANGE = &H1A 'INI File Update Private Const HWND_BROADCAST = &HFFFF& 'Send To All Private Const WM_SETTINGCHANGE = &H1A 'Setting Change Private Const SMTO_ABORTIFHUNG = &H2 'Stop If Hang Private Const WM_COMMAND As Int32 = &H111 'Send Command Private Const WM_USER As Int32 = &H400 'User Private Const WM_SETTEXT = &HC 'Change Text Private Const WM_GETTEXT = &HD 'Get Text
If you read the comments, you will basically get an idea of each API’s function. If this is the first time you encounter APIs, I’d advise you to read this article to understand them better. I will, of course, go in detail as you go on.