none
Hide Tab from Taskbar

    Question

  •  

    How do I hide MyApplication [MFC Dialog Based] Tab from taskbar.

     

    For hiding myapplication from taskbar I am using ITaskbar2 code is below

     

    Code Snippet

    CoInitialize(NULL);

    ITaskbarList2* pITask = NULL;

    HRESULT hr = CoCreateInstance(CLSID_TaskbarList,NULL,CLSCTX_INPROC_SERVER,IID_ITaskbarList2,(LPVOID*) &pITask);

    hr = pITask->HrInit();

    hr = pITask->DeleteTab(hwnd);

    pITask->Release();

    CoUninitialize();

     

     

    If any dialog box or message box is popup my application again display in taskbar, I dont want to use any timer and repeating above code for all dialog and messege box.

     

    Is there any common solution for hide application from taskbar ?

     

     

    Kind Regards

     

    Manoj Jangid

    Wednesday, May 21, 2008 10:19 AM

Answers

  • The Application Window property of the dialog should be False.  That's still not enough to convince Windows since it is a top level window without an owner.  Setting Tool Window to True works...
    Wednesday, May 21, 2008 12:24 PM
  • That's going to be awfully hard to do in MFC.  Windows Forms does it by destroying the window, then recreating is with different window styles.  MFC is not going to like that.

    In an SDI application, you need to change the window styles in the PreCreateWindow() method.  For example:

    BOOL CMainFrame:Stick out tonguereCreateWindow(CREATESTRUCT& cs)
    {
        if( !CFrameWnd:Stick out tonguereCreateWindow(cs) )
            return FALSE;
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs

        cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
        cs.dwExStyle |= WS_EX_TOOLWINDOW;
        cs.lpszClass = AfxRegisterWndClass(0);
        return TRUE;
    }

    Wednesday, May 21, 2008 3:22 PM
  • This is how I have made a taskbar iconless dialog application (I think it will work for SDI app also):

     

    Create an invisible window in InitInstance and set it as the owner of the dialog.

     

    Code Snippet

     if ( m_wndOwner.m_hWnd == NULL )
     {
      LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);

      if ( !m_wndOwner.CreateEx(0, pstrOwnerClass, _T(""),
        WS_POPUP,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL, 0) )
       return FALSE;
     }

     CFtpMyIpDlg dlg(&m_wndOwner);
     m_pMainWnd = &dlg;
     int nResponse = dlg.DoModal();
     if (nResponse == IDOK)
     {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with OK
     }
     else if (nResponse == IDCANCEL)
     {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with Cancel
     }

     if (m_wndOwner.m_hWnd != NULL)
      m_wndOwner.DestroyWindow();

     // Since the dialog has been closed, return FALSE so that we exit the
     //  application, rather than start the application's message pump.
     return FALSE;

     

     

    Remove the WS_EX_APPWINDOW for the window in OnInitDialog for the dialog

     

     

    Code Snippet
     ModifyStyleEx( WS_EX_APPWINDOW, 0 );
     CDialog::OnInitDialog();

     

     

    This removes the window from the taskbar but not from the Alt+Tab list.

     

    /Ruben

    RJJournal

     

    Wednesday, May 21, 2008 5:14 PM

All replies

  • The Application Window property of the dialog should be False.  That's still not enough to convince Windows since it is a top level window without an owner.  Setting Tool Window to True works...
    Wednesday, May 21, 2008 12:24 PM
  • Thanks for your reply

     

    In above setting application icon removed from taskbar but it is displaying above start button.

     

    but my requirement is little bit different.

    1. If my application minimized then icon should display in taskbar else removed from taskbar

    2. it is not working with SDI application

     

    Regards

     

    Manoj Jangid

    Wednesday, May 21, 2008 1:22 PM
  • That's going to be awfully hard to do in MFC.  Windows Forms does it by destroying the window, then recreating is with different window styles.  MFC is not going to like that.

    In an SDI application, you need to change the window styles in the PreCreateWindow() method.  For example:

    BOOL CMainFrame:Stick out tonguereCreateWindow(CREATESTRUCT& cs)
    {
        if( !CFrameWnd:Stick out tonguereCreateWindow(cs) )
            return FALSE;
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs

        cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
        cs.dwExStyle |= WS_EX_TOOLWINDOW;
        cs.lpszClass = AfxRegisterWndClass(0);
        return TRUE;
    }

    Wednesday, May 21, 2008 3:22 PM
  • This is how I have made a taskbar iconless dialog application (I think it will work for SDI app also):

     

    Create an invisible window in InitInstance and set it as the owner of the dialog.

     

    Code Snippet

     if ( m_wndOwner.m_hWnd == NULL )
     {
      LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);

      if ( !m_wndOwner.CreateEx(0, pstrOwnerClass, _T(""),
        WS_POPUP,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL, 0) )
       return FALSE;
     }

     CFtpMyIpDlg dlg(&m_wndOwner);
     m_pMainWnd = &dlg;
     int nResponse = dlg.DoModal();
     if (nResponse == IDOK)
     {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with OK
     }
     else if (nResponse == IDCANCEL)
     {
      // TODO: Place code here to handle when the dialog is
      //  dismissed with Cancel
     }

     if (m_wndOwner.m_hWnd != NULL)
      m_wndOwner.DestroyWindow();

     // Since the dialog has been closed, return FALSE so that we exit the
     //  application, rather than start the application's message pump.
     return FALSE;

     

     

    Remove the WS_EX_APPWINDOW for the window in OnInitDialog for the dialog

     

     

    Code Snippet
     ModifyStyleEx( WS_EX_APPWINDOW, 0 );
     CDialog::OnInitDialog();

     

     

    This removes the window from the taskbar but not from the Alt+Tab list.

     

    /Ruben

    RJJournal

     

    Wednesday, May 21, 2008 5:14 PM
  • This article may help you http://www.frostcode.info/common-articles/how-to-remove-taskbar-entry-of-a-mfc-application.html
    Friday, October 02, 2009 6:45 AM
  • This pseudo-site (frostcode) is laughable (spamming in all forums with newbie and horrible code...)
    Friday, October 02, 2009 8:34 AM