Click here to Skip to main content
12,821,494 members (24,274 online)
Click here to Skip to main content
Add your own
alternative version


1 download
66 bookmarked
Posted 5 Jan 2000

Creating an application with no taskbar icon

, 5 Jan 2000 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple method to create a main window that does not appear in the windows taskbar

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
    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,
                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.


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.

You may also be interested in...


Comments and Discussions

General...or as they tell it in MSDN... Pin
Mathias14-Jan-02 0:14
memberMathias14-Jan-02 0:14 
GeneralRe: ...or as they tell it in MSDN... Pin
Chris Maunder14-Jan-02 0:33
memberChris Maunder14-Jan-02 0:33 
GeneralRe: ...or as they tell it in MSDN... Pin
Mathias14-Jan-02 0:59
memberMathias14-Jan-02 0:59 
GeneralRe: ...or as they tell it in MSDN... Pin
Elmue14-May-12 8:09
memberElmue14-May-12 8:09 
AnswerThe perfect solution Pin
Elmue14-May-12 8:20
memberElmue14-May-12 8:20 
To get to the perfect solution:

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)

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)

To avoid the latter the !invisible window! needs the flag WS_EX_TOOLWINDOW.

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 (!::IsWindow(mi_Invisible.m_hWnd))
            DWORD u32_ExStyle = WS_EX_TOOLWINDOW;
            #if SHOW_TASKSWITCH_ICON
                u32_ExStyle = 0;

            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);
        cs.hwndParent = mi_Invisible.m_hWnd; &= ~WS_MINIMIZEBOX;
    return TRUE;

"#32770" is the class name for dialogs.

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... Pin
Anonymous22-Jul-03 21:14
sussAnonymous22-Jul-03 21:14 
GeneralRe: ...or as they tell it in MSDN... Pin
Anonymous22-Jul-03 21:18
sussAnonymous22-Jul-03 21:18 

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

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

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