How to dynamically show/hide the Taskbar application button

An issue is to implement the show/hide taskbar application
button from within the window-application in Microsoft Visual C++
environment using MFC. Hiding the taskbar can be accomplished by
ITaskbarList COM interface which requires necessary COM-handling
overhead. Unfortunately, this interface is provided by
Shell32.dll version 4.71 (and higher) only. Normally, there is
not even a standard header in Microsoft Visual C++ 6.0 supporting
this feature. Although the full source code is obtainable in
Microsoft MSDN Source Library, the idea was to implement this
feature as simple as possible just using the standard WINDOWS

Showing/hiding taskbar buttons normally work in conjunction
with registering an application icon in the system tray (adding
or removing an icon to the system tray is equally described on
other pages).

There is no big problem to implement visual behavior of
taskbar buttons while creating the main application window. It
does just to set an invisible Popup or Overlapped window as the
parent window of the main application window (generally derived
from CFrameWnd) in it’s PreCreateWindow() virtual method. This
solution is well-known and well documented. But how to restore
the visibility of the hidden taskbar button again in runtime.
Let’s figure out:

First Step:

Create the modeless invisible dialog using resource dialog
with ID e.g. IDD_FRAMEOWNER (empty dialog with no borders):

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
if (!CFrameWnd::PreCreateWindow(cs)) return FALSE;
if (!m_bOwnerCreated) // “dialog-is-created” flag
// m_MainFrameOwner – CDialog object mapped to the resource dialog template
m_bOwnerCreated = m_MainFrameOwner.Create(IDD_FRAMEOWNER);
if (m_bOwnerCreated) m_MainFrameOwner.ShowWindow(SW_HIDE);

// set the dialog as a parent of CMainFrame window
if (m_bOwnerCreated)
cs.hwndParent = m_MainFrameOwner.GetSafeHwnd();

return TRUE;

Last Step

Define the method like this:

BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)
if (!m_bOwnerCreated) return FALSE;


if (bVisible)
ModifyStyleEx(0, WS_EX_APPWINDOW);
ModifyStyleEx(WS_EX_APPWINDOW, 0);


return TRUE;

When we need to show the taskbar button that was previously
hidden we have to modify the CMainFrame window ex-style by adding
WS_EX_APPWINDOW flag. This flag suppresses the behavior of the
owner window and the application itself becomes visible (from the
taskbar point of view).

On the other hand removing WS_EX_APPWINDOW flag forces the
taskbar to find the owner window relying to the CMainFrame window
– which is invisible and the button gets disappeared. Using
ShowWindow() method is needed to make the necessary refreshing of
the taskbar itself after changing the CMainFrame window ex-style.

More by Author

Must Read