How to dynamically show/hide the Taskbar application button
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;
ShowWindow(SW_HIDE);
if (bVisible)
ModifyStyleEx(0, WS_EX_APPWINDOW);
else
ModifyStyleEx(WS_EX_APPWINDOW, 0);
ShowWindow(SW_SHOW);
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.

Comments
Hammad is very genius Guy Tell Me About System Tray
Posted by Legacy on 09/16/2003 12:00amOriginally posted by: Ramzan
ReplyA method for doing this in CDialog-based apps that Really Works
Posted by Legacy on 03/11/2003 12:00amOriginally posted by: Warren Young
I have an article here on CodeGuru that does the same sort of thing as Filipp's code, but for CDialog-based apps. Filipp's code only seems to work with CWnd-based apps. There are several comments attached to this article try to address this issue, but none of them seem to help.
My article's URL is http://codeguru.com/shell/tbhide.html
ReplyHide Icons of OTHER applications in the SysTray
Posted by Legacy on 02/02/2003 12:00amOriginally posted by: jose rizal
How do you hide the selected icons of OTHER applications in the system tray without terminating them using Visual Basic or VC++?
ReplyHow do you hide a "website's" taskbar button.
Posted by Legacy on 07/28/2002 12:00amOriginally posted by: Charles
Hey there guys and gals. Just found this forum on yahoo as I was doing some research. Ok here it is. I would like to create a webpage that will not have a taskbar button.
In other words, everytime you open a site, it will appear on your taskbar... right? Well I want know how I can create a "floating" site that does not display itself on the task bar.
Can this be acheived with simple scripting or do I have to embed the page in some form of application that floats and then hide the application itself. Been racking my brain on this one for a while. I really don't want to have to create a software (which I've never done) to achieve this goal. Your response would be most appreciated.
ReplyIntertsting
Posted by Legacy on 02/15/2001 12:00amOriginally posted by: Ravish.S
The given article is wonderful and informative.
ReplyI got it ! A Taiwanese said.
Posted by Legacy on 12/05/2000 12:00amOriginally posted by: Powen Ko
Thank you very much,
ReplyI want find a hide window programming of Visual C++ that spent many days,
Thank you for you writing this programming.
Thank you Again.
Enhanced solution
Posted by Legacy on 11/30/2000 12:00amOriginally posted by: Yair Konfino
Hi All !
I made some changes to the ShowTaskBarButton function.
Use it like this :
BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)
{
ShowWindow(SW_HIDE);
if (bVisible)
ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW);
else
ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);
ShowWindow(SW_SHOW);
return TRUE;
}
Don't forget to set the owner dialog as one with no borders and as a child.
Look at the MSDN article :
ReplyHOWTO: Prevent a Window from Appearing on the Taskbar.
How to put the application in the systray
Posted by Legacy on 10/31/2000 12:00amOriginally posted by: Mala
Replythe solution for CDialog-based apps
Posted by Legacy on 08/31/2000 12:00amOriginally posted by: Manfred Zinner
The shell does not create a taskbar button if the window being created has the WS_EX_TOOLWINDOW style. This is well-known, but this trick did not seem to work for Dialog-based apps.
The problem with Dialog-based apps is that the wizard-generated resource file creates the main dialog with an extended style bit WS_EX_APPWINDOW set. This is not visible / changeable in the resource editor. checking or unchecking 'Tool Window' in the resource editor will toggle between
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_APPWINDOW
and
EXSTYLE WS_EX_APPWINDOW
; with both settings a taskbar button will be created.
To solve this, open the .rc file, selecting 'Open As: Text'
in the file open dialog box. search for the line
EXSTYLE WS_EX_APPWINDOW
and replace WS_EX_APPWINDOW with WS_EX_TOOLWINDOW.
Save, recompile and start - no taskbar button will be created.
ReplyTaskbar button not pressed when window brought to top
Posted by Legacy on 08/18/2000 12:00amOriginally posted by: Christian Carrillo
I haven't been able to fix this problem.
When the taskbar button -is displayed- and the window
is not on top, and you click the window's caption to bring
it to the top, it comes to the top but its button in the
taskbar is not pressed.
It's unclear why the disconnection between the main
Replywindow and the taskbar should cause the taskbar not to
update. There may not be a way around this problem.
If anyone has any suggestions, please let me know!
Loading, Please Wait ...