Hide Your Taskbar for Full Screen Apps

This article will explain how to make optimal use of your computer screen by using a macro to hide your taskbar while an application is being viewed in fullscreen mode. This VBA will help you dedicate a keyboard shortcut so that hiding your taskbar is quick and simple.

Macro to Hide Taskbar for Full Screen Apps

You may use this macro to program your computer to auto-hide your taskbar when an application is in fullscreen mode:

'*************************

'*** Lermite ******

'*** 06/03/2010 ******

'*************************

Option Explicit

Public Bascule As Boolean

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

Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Public Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As AppBarData) 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

Private Type POINTAPI

X As Long

Y As Long

End Type

Private Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public Type AppBarData

cbSize As Long

hwnd As Long

uCallbackMessage As Long

uEdge As Long

rc As RECT

lParam As Long

End Type

Private Type WINDOWPLACEMENT

Length As Long

FLAGS As Long

showCmd As Long

ptMinPosition As POINTAPI

ptMaxPosition As POINTAPI

rcNormalPosition As RECT

End Type

Public WinPlacement As WINDOWPLACEMENT

Public Const ABS_ALWAYSONTOP = &H2

Public Const ABS_AUTOHIDE = &H1

Public Const ABM_GETSTATE = &H4

Public Const ABM_SETSTATE = &HA

' Trouver le hwnd de la barre des tâches

Private Function GetHwndBT() As Long

GetHwndBT = FindWindow("shell_traywnd", "")

End Function

Private Function BarData() As Integer

Dim BarDt As AppBarData

BarData = SHAppBarMessage(ABM_GETSTATE, BarDt)

End Function

'Retourne true si la barre des tâches est rétractible

Public Function BarMode() As Boolean

Dim ret As Integer

ret = BarData()

BarMode = (ret = ABS_AUTOHIDE + ABS_ALWAYSONTOP Or ret = ABS_AUTOHIDE)

End Function

'Applique les propriétés à la barre des taches

'Mode = 0 : voir la barre des tâche

'Mode = 1 : cache la barre des tâches

Public Sub ChangeTaskBar(Mode As Long)

Dim BarDt As AppBarData

Dim ret As Long

'Entrée des paramètres

BarDbSize = Len(BarDt)

BarDt.hwnd = GetHwndBT

BarDt.lParam = Mode

'Applique

ret = SHAppBarMessage(ABM_SETSTATE, BarDt)

If ret = 0 Then

Call MsgBox("erreur lors de l'appel de SHAppBarMessage", vbCritical + vbOKOnly, "Erreur")

End If

End Sub

Sub MaximizeAppli()

Static a As Boolean

Static Changer As Integer

If Changer = 0 Then

'Voir si la barre des tâches est rétractible

Changer = IIf(BarMode, 1, 2)

End If

a = Not a

If Changer = 2 Then

'la barre des tâches n'est pas rétractible, ont la retracte / Ressort

Call ChangeTaskBar(Abs(a))

End If

'L'appli sera toujours maximizée plein écran.

Application.WindowState = IIf(a, xlMaximized, xlNormal)

End Sub

Practical Uses for Taskbar Macro

The first use of this macro is as a keyboard shortcut. To set this, go to your ribbon and click on Macro. Select the MaximizeAppli macro. Then, click on Option and assign a letter to the shortcut.

The second use of this macro is as a form button. You can do this by assigning the MaximizeAppli function to a button.

This macro may also be used with a button on a UserForm. To do this, the userform must be named something containing Show0 in the button's code:

Private Sub CommandButton1_Click()

MaximizeAppli

Dim T, L

'Exemple pour positionner le bouton aux environs des boutons système de l'appli.

L = Application.Left + Application.Width - UFbouton.Width - 60

T = Application.Top + 2

Me.Move L, T, 40, 14 ' à adapter

End Sub

You can download a demo workbook demo of this macro here.

Spread the love

Leave a Comment