Example Apps for Businesses, Schools & Developers

Version 1.5           Approx 0.6 MB (zipped)                 First Published 13 June 2024


Introduction

This article was originally prompted by a very unusual request from patriciaxxx at Utter Access forum back in 2017:
      Don’t Show Application Icon In Taskbar

The reason for wanting to do this was never fully explained during this lengthy thread.

Personally, I find the taskbar icon very useful for selecting applications and can only think of one valid reason for wanting to hide it - see later in this article.

It should also be stated that when the taskbar icon is hidden, the application cannot be selected using Alt+Tab.
Restoring the taskbar icon also makes the app available for selection using this keyboard shortcut.

Nevertheless, I was intrigued enough to find a solution using the SetWindowLong API which I used as part of my example app: Control the Application Interface

However, at the time, my solution only worked when the application window was hidden, which the original poster explicitly stated they didn't want!
Recently I updated the code so it now works with the application window visible or hidden. Doing this was surprisingly difficult.

Former MVP, Philipp Stiefel, devised a totally different approach using COM programming
Once again, achieving this result was difficult to implement.
See Philipp's excellent article: How to hide the Taskbar Button of a window. - An excursion to the raw COM API with VBA

Philipp recently updated the code for 64-bit compatibility. I have adapted his code to also work with the application window hidden.

The two solutions are very different from each other but both achieve exactly the same results.
Both solutions are included in the example app so you can select whichever method you prefer.



Example App

The example app opens to a start form with two buttons:

StartForm
Click the left button to open a new form which uses the Taskbar List code developed by Philipp.

Click the right button to open an almost identical form whch uses the SetWindowLong API code that I developed.

Taskbar List form

TaskbarList Form
SetWindowLong form

SetWindowLong Form


Click the two buttons to toggle the Access taskbar icon and/or the application window visible or hidden.
The button captions are automatically updated when clicked

I have created a short video (5:12) to demonstrate the effect of doing this in each case.

You can watch the Hide the Taskbar Icon video on my Isladogs YouTube channel or you can click below:



If you liked the video, please subscribe to my Isladogs on Access channel on YouTube. Thanks.


NOTE:
1.   Both forms are popups so they can be used with the application window hidden

2.   When the app window is visible, the taskbar icon is for the application. 'Killing' the taskbar icon (by clicking the X) will shut down the application properly.

TaskbarAppIcon
3.   However, when the app window is hidden, the taskbar icon is for the form.

TaskbarFormIcon
      Killing the taskbar icon will therefore close the only part of the application that was visible.
      This will leave a hidden instance of Access as a background process. This will need to be terminated by clicking End Task in the Task Manager

TaskManager
4.   Changing a popup form to design view with the application window hidden has the same effect.
      As the form isn't a popup in design view, it will also become hidden leaving a hidden instance of Access that can only be terminated in Task Manager.

      To prevent this, I have disabled the right click context menu by setting Shortcut Menu = No in the property sheet for both popup forms.

5.   The attached zip file contains a second version of the app which uses a custom application icon.

CustomIcon
      The functionality is identical to the other version with one exception.
      When the application window is hidden, the custom taskbar icon reverts to the standard Access icon

AccessIcon
      This is an artefact of the SetWindowLong API code used to hide the app window. I have not found a workaround to prevent this happening.



Why Hide the Taskbar Icon?

Throughout this article I have also heavily emphasised using this code with the application window hidden.
This is because the only benefit I can see for hiding the taskbar icon is to prevent users killing the icon without realising this will leave a hidden instance of Access,

When the application window is visible, I see no possible benefit in hiding the taskbar icon. I would be interested in knowing why anyone would ever want to do this.



SetWindowLong API Code Summary

My Hide Taskbar Icon button code based on the SetWindowLong API is as follows:

Private Sub cmdTaskbarIcon_Click()

      'hide the VBE if visible
      Application.VBE.MainWindow.Visible = False

     'toggle the button caption
      If cmdTaskbarIcon.Caption = "Hide Taskbar Icon" Then
            cmdTaskbarIcon.Caption = "Show Taskbar Icon"
      Else
            cmdTaskbarIcon.Caption = "Hide Taskbar Icon"
      End If

      'toggle the taskbar icon
      If cmdAppWindow.Caption = "Hide Application Window" Then
            ToggleTaskbarIcon hWndAccessApp       'show/hide app window taskbar icon
            ToggleFormWindowIcon Me       'show/hide form window taskbar icon
      Else
            ToggleFormWindowIcon Me       'show/hide form window taskbar icon
      End If

End Sub


The related APIs and supporting code are included in module modDatabaseWindow:

Option Compare Database
Option Explicit

'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'Sets the specified window's show state (normal/minimized/maximized/restore etc)
Declare PtrSafe Function ShowWindow Lib "user32" _
      (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long

'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlonga
'Retrieves information about the specified window. Superceded by GetWindowLongPtr for pointers/handles
Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
      (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long

'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlonga
'Changes an attribute of the specified window - used here to set new extended window styles
Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
      (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

'===========================================

/* Window field offsets for Set/GetWindowLong() */
'Retrieves the extended window styles.
Public Const GWL_EXSTYLE As Long = -20

'/* Extended Window Styles */
'Forces a top-level window onto the taskbar when the window is visible.
Public Const WS_EX_APPWINDOW As Long = &'H40000
Public Const WS_EX_TOOLWINDOW = &H80

'--------------------------------------

Function ToggleFormWindowIcon(frm As Access.Form)
      'hide/show the taskbar form icon
      SetWindowLong frm.hwnd, GWL_EXSTYLE, GetWindowLong(frm.hwnd, GWL_EXSTYLE) Xor WS_EX_APPWINDOW
End Function

Public Sub ToggleTaskbarIcon(lHwnd As Long)
      'hide/show the taskbar app window icon
      SetWindowLong lHwnd, GWL_EXSTYLE, GetWindowLong(lHwnd, GWL_EXSTYLE) Xor WS_EX_TOOLWINDOW
End Sub


NOTE:
The code used for hiding the application window is fully explained in my article: Control the Application Interface



Taskbar List COM Interface Code Summary

The Hide Taskbar Icon button code depends on the ITaskbar List COM interface code by Philipp Stiefel:

Private Sub cmdTaskbarIcon_Click()
Dim tb As clsTaskbarList
Set tb = New clsTaskbarList

     'close the VBE if open
     Application.VBE.MainWindow.Visible = False

     If cmdAppWindow.Caption = "Show Application Window" Then
           'application window hidden
            If cmdTaskbarIcon.Caption = "Hide Taskbar Icon" Then
                 'delete taskbar icon for the active form
                  tb.DeleteTab Forms(0).hwnd
                  cmdTaskbarIcon.Caption = "Show Taskbar Icon"
            Else
                  'restore taskbar icon for the active form
                  tb.AddTab Forms(0).hwnd
                  cmdTaskbarIcon.Caption = "Hide Taskbar Icon"
            End If
      Else
            'application window visible
            If cmdTaskbarIcon.Caption = "Hide Taskbar Icon" Then
                  'delete taskbar icon for the application
                  tb.DeleteTab Application.hWndAccessApp
                  'if app window was hidden & then restored, the active form taskbar icon remains
                  'also delete taskbar icon for the active form
                  tb.DeleteTab Forms(0).hwnd
                  cmdTaskbarIcon.Caption = "Show Taskbar Icon"
            Else
                  'restore taskbar icon for the application
                  tb.AddTab Application.hWndAccessApp
                  cmdTaskbarIcon.Caption = "Hide Taskbar Icon"
            End If
      End If

End Sub


The AddTab and DeleteTab code are a very small part of the class module clsTaskbarList

Public Sub AddTab(ByVal hwnd As LongPtr)
      InvokeITaskbarListMember ITaskbarListVtable.OfAddTab, "AddTab", hwnd
End Sub

Public Sub DeleteTab(ByVal hwnd As LongPtr)
      InvokeITaskbarListMember ITaskbarListVtable.OfDeleteTab, "DeleteTab", hwnd
End Sub


Please see the class module for full details of the fairly complex code involved.
Also, please read Philipp's article for a better understanding of how it works.



Download:

Click to download a zip file containing two versions of the example app - with/without a custom icon. All required code is supplied with the two apps.
      HideTaskbarIcon_v1.5      (ACCDB - zipped)



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington           Mendip Data Systems                 Last Updated 13 June 2024



Return to Example Databases Page




Return to Top