Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How To Hide A Window in TaskBar

0.00/5 (No votes)
16 Apr 2004 1  
This article explains how to hide a window's name in the taskbar while the window itself is still active.

Introduction

Sometimes we may want to make an app which doesn't actually need an annoying box in the taskbar. I hope this snippet will help.

Steps

  1. Global Declaration

    Here is some short explanation about the interface used:

    • DECLARE_INTERFACE(iface) is used to declare an interface that does not derive from a base interface.
    • DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface that does derive from a base interface. This is the one that is used. And the interface will be derived from IUnknown interface.

    And then, let's create an alias definition for the derived interface.

    DECLARE_INTERFACE_(ITaskbarList,IUnknown)
    {
    STDMETHOD(QueryInterface)(THIS_ REFIID riid,LPVOID* ppvObj) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    STDMETHOD(ActiveTab)(HWND) PURE;
    STDMETHOD(AddTab)(HWND) PURE;
    STDMETHOD(DeleteTab)(HWND) PURE;
    STDMETHOD(HrInit)(HWND) PURE;
    };
    //alias
    
    typedef ITaskbarList *LPITaskbarList;
  2. In the Dialog Based Class declaration

    Here is up to you, whether you want to declare the pTaskbar as an attribute of a Dialog class or not. It's not a problem, actually, since the implementation (next step) will only need the window handle (HWND).

    class CMyDlg : public CDialog
    {
    .
    .
    //Init our Taskbar handler
    
    LPITaskbarList pTaskbar;
    .
    .
    }

    Don't forget to set the pTaskbar to NULL in the construction method for your dialog class.

  3. Initialization
    BOOL CMyDlg::OnInitDialog()
    {
    .
    .
    //initializes the Component Object Model(COM)
    
    CoInitialize(0);
    //We call below function since we only need to create one object
    
    CoCreateInstance(CLSID_TaskbarList,0, 
      CLSCTX_INPROC_SERVER,IID_ITaskbarList,(void**)&pTaskbar);
    //Below function will initialize the taskbar list object
    
    pTaskbar->HrInit(this);
    .
    .
    .
    }
  4. Implementation

    This is the function that you can use to hide the "box" in taskbar.

    void CMyDlg::DeleteTaskbar()
    {
    //Hide it
    
    pTaskbar->DeleteTab(this);
    }

Try the other methods for pTaskbar, and you will experience some stuff.

Forgive me if this article doesn't explain much. My purpose is just to provide another alternative. Since this "way" hasn't been posted yet.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here