Click here to Skip to main content
Click here to Skip to main content

Creating an application with no taskbar icon

By , 5 Jan 2000
Rate this:
Please Sign up or sign in to vote.

This is a technique I first saw in Mike Blaszczak's 'stealth' program.

It is desirable sometimes to not have your application window show up in the taskbar. For instance, you may have an application resides in the system tray, and since it already has a system tray icon, having the extra icon in the taskbar is needless duplication. A simple way to create a window that will not have an icon in the taskbar is to create a separate invisible window, and have that invisible window be the parent of your applications window.

The way to do this, and still allow your application's window to remain visible, is to set the invisible window as parent in your application's PreCreateWindow override.

First, declare a window member variable in your Main Frame class:

class CMainFrame : public CFrameWnd
{
...
protected:
    CWnd m_wndInvisible;
...

Then override CMainFrame::PreCreateWindow:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CFrameWnd::PreCreateWindow(cs))
         return FALSE;

     // Create invisible window
     if (!::IsWindow(m_wndInvisible.m_hWnd))
     {
        LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);
        if (!m_wndInvisible.CreateEx(0, pstrOwnerClass, _T(""), WS_POPUP,
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                NULL, 0))
            return FALSE;
     }

    cs.hwndParent = m_wndInvisible.m_hWnd;

    return TRUE;
}

That's all you need to do! The invisible window will be automatically destroyed when the main application closes.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberzenkicpp30-Nov-12 13:17 
Newssumthing missing Pinmemberaddy80823-Apr-07 3:09 
GeneralVC++ Code to add application icon to the Task Manager PinmemberSmitha Rao27-Sep-06 4:03 
GeneralRe: VC++ Code to add application icon to the Task Manager Pinmemberhari_honey19-Aug-08 19:53 
Questionalt+tab PinsussAnonymous12-Sep-05 1:41 
AnswerRe: alt+tab PinmemberTorres O.19-Jan-06 12:26 
General[Message Removed] Pinmembernompel6-Oct-08 9:18 
AnswerDon't do that PinmemberElmue14-May-12 7:37 
AnswerRe: alt+tab Pinmembersam t. xu21-Apr-06 10:11 
AnswerRe: alt+tab problem solved PinmemberElmue14-May-12 7:29 
QuestionHow I can add an icon in the left superior corner? Pinsussleoncar12-Jan-04 18:14 
QuestionHow I can add an icon in the left superior corner? Pinmemberleolim12-Jan-04 18:13 
QuestionHow to make it in Visual Basic? PinmemberMickey_vip6-Aug-03 12:40 
GeneralIncorrect icon in system dialog When Alt+Tab Pinsusskimdaejeong24-Apr-03 23:31 
QuestionHow to Create an application(base dialog) with no taskbar icon? Pinmemberzhangyifei25-Nov-02 3:40 
GeneralThis man is just great :) PinmemberAnonymous27-Mar-02 14:59 
General...or as they tell it in MSDN... PinmemberMathias13-Jan-02 23:14 
GeneralRe: ...or as they tell it in MSDN... PinmemberChris Maunder13-Jan-02 23:33 
GeneralRe: ...or as they tell it in MSDN... PinmemberMathias13-Jan-02 23:59 
GeneralRe: ...or as they tell it in MSDN... [modified] PinmemberElmue14-May-12 7:09 
AnswerThe perfect solution [modified] PinmemberElmue14-May-12 7:20 
To get to the perfect solution:
 
1.)
Do NOT use WS_EX_TOOLWINDOW for the visible window because this flag shows an ugly caption bar and removes the Minimize, Maximize buttons from the caption bar. (teensy weensy as Chris says)
 
2.)
Using an invisible parent for your visible window as described in the article makes the taskbar button disappear, which is what we want. BUT in the Task-Switch window (when hitting ALT + TAB) the invisible window is listed, which is ugly. (it does not even have an icon)
 
3.)
To avoid the latter the !invisible window! needs the flag WS_EX_TOOLWINDOW.
 
4.)
Another option (if you want the Icon to appear in the Task-Switch window) is to explicitly set the icon for the invisible window.
 
So here the perfect code:
 

Header file:
#define SHOW_TASKBAR_BUTTON    FALSE  // Show this window in the Taskbar
#define SHOW_TASKSWITCH_ICON   TRUE   // Show this window in the Task-Switch dialog

CWnd mi_Invisible;
 

CPP File:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CMDIFrameWnd::PreCreateWindow(cs) )
        return FALSE;
    
    #if !SHOW_TASKBAR_BUTTON
        if (!::IsWindow(mi_Invisible.m_hWnd))
        {
            DWORD u32_ExStyle = WS_EX_TOOLWINDOW;
            #if SHOW_TASKSWITCH_ICON
                u32_ExStyle = 0;
            #endif
 
            if (!mi_Invisible.CreateEx(u32_ExStyle, L"#32770", L"Invisible", 
                                       WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 
                                       CW_USEDEFAULT, CW_USEDEFAULT, NULL, 0))
                return FALSE;
 
            #if SHOW_TASKSWITCH_ICON
                mi_Invisible.SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
                mi_Invisible.SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), FALSE);
            #endif
        }
    
        cs.hwndParent = mi_Invisible.m_hWnd;
        cs.style &= ~WS_MINIMIZEBOX;
    #endif
    return TRUE;
}
 
P.S.
"#32770" is the class name for dialogs.
 
P.P.S.
The Minimze button does not make sense for a window without taskbar button

modified 15-May-12 12:48pm.

GeneralRe: ...or as they tell it in MSDN... PinsussAnonymous22-Jul-03 20:14 
GeneralRe: ...or as they tell it in MSDN... PinsussAnonymous22-Jul-03 20:18 
QuestionHas anyone done this with Visual C++ 6.0? PinmemberSixString29-Nov-01 19:47 
AnswerRe: Has anyone done this with Visual C++ 6.0? PinmemberAlbert van Peppen18-Dec-02 3:03 
GeneralTop banana! PinmemberBaz3-Apr-01 23:16 
QuestionWhat About Console Application? PinmemberAnonymous12-Jan-01 12:32 
GeneralJava PinsussNick20-Jul-00 12:48 
QuestionHow do you do this in Delphi? PinsussRick Ashford13-Apr-00 19:01 
QuestionHow to avoid task being removed from task list ( in the Task Manager)? PinsussBernd Giesen7-Apr-00 3:23 
QuestionWorking for Dialog based Apps!! The correct way? PinsussAlbert van Peppen6-Apr-00 2:52 
AnswerRe: Working for Dialog based Apps!! The correct way? PinsussMartin Schmid16-Apr-00 17:57 
AnswerRe: Working for Dialog based Apps!! The correct way? PinmemberAnonymous14-May-01 3:05 
AnswerRe: Working for Dialog based Apps!! The correct way? PinmemberWolle4-Aug-01 0:21 
GeneralRe: Working for Dialog based Apps!! The correct way? PinmemberWolle4-Aug-01 8:30 
AnswerRe: Working for Dialog based Apps!! The correct way? PinmemberRobJones28-Nov-01 15:48 
GeneralRe: Working for Dialog based Apps!! The correct way? PinmemberAlbert van Peppen9-Jan-02 21:14 
AnswerRe: Working for Dialog based Apps!! The correct way? PinmemberRiccardo Modesti18-Jan-02 2:32 
GeneralRe: Working for Dialog based Apps!! The correct way? PinmemberWaleed17-Apr-02 13:03 
AnswerRemove WS_EX_APPWINDOW easier. and TOGGLE ...? PinmemberBehzad Ebrahimi17-Dec-02 21:46 
GeneralRe: Remove WS_EX_APPWINDOW easier. and TOGGLE ...? Pinsussotwesten14-Apr-03 5:12 
AnswerRe: Working for Dialog based Apps!! The correct way? PinsussAnonymous16-Nov-04 18:41 
AnswerRe: Working for Dialog based Apps!! The correct way? - How to fix the ALT+TAB icon PinmemberDLChambers10-Jan-07 7:17 
AnswerRe: Working for Dialog based Apps!! The correct way? PinmemberKienNT787-Mar-08 20:22 
GeneralNot totally invisible Pinsusskabir20-Mar-00 4:30 
GeneralRe: Not totally invisible PinmemberAliAkbar Rashidi2-Apr-01 22:52 
GeneralRe: Not totally invisible PinmemberShengqian Ji19-Apr-02 3:33 
GeneralIts far easier to do with dialog Apps ! PinsussColin Davies13-Jan-00 9:03 
GeneralRe: Its far easier to do with dialog Apps ! PinsussMartin MacRobert25-Jan-00 9:58 
GeneralRe: Need to set 2 properties also PinsussVince Buttigieg23-Mar-00 13:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 6 Jan 2000
Article Copyright 2000 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid