locked
MFC Dialog Window RRS feed

  • Question

  • I have created an MFC Dialog based application. I don't want that application to be displayed in Taskbar, even if the window is VISIBL. How can I Prevent that?
    Adeel
    Tuesday, January 11, 2011 11:37 AM

Answers

  • The easies way is using the WS_EX_TOOLWINDOW style. Than you have a toolwindow with a small caption.

    If you want a dialog with a normal dialog caption, than your dialog window has to be a child of a (invisible) ToolWindow.

    In my opinion a normal popup window should have a taskbar button.

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Tuesday, January 11, 2011 1:29 PM
  • You may want to consider making this a tray application as well.  This class makes it pretty simple to implement:

    http://www.naughter.com/ntray.html

    Tom

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Wednesday, January 12, 2011 7:26 PM
  • In Dialog class OnInitDailog function add this code:

    ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE platform embedded development.
    • Marked as answer by maverick786us Friday, January 14, 2011 5:53 AM
    Thursday, January 13, 2011 6:02 AM
  • >I have created an MFC Dialog based application. I don't want that application to be displayed in Taskbar, even if the window is VISIBL. How can I Prevent that?

    Create a normal MFC dialog application, and an invisible top level
    window before the dialog constructor. Pass the invisible window as the
    parent of the dialog and call DoModal.

    Modify the style of the dialog window in OnInitDialog to remove the
    WS_EX_APPWINDOW style.

    BOOL CInvDlgApp::InitInstance()
    {
        // Normal MFC generated code...

        // Doctored version of BekiM's stealth code

        // (m_wndOwner is a member CWnd I've added to
        // the application class)

        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;
        }

        CInvDlgDlg 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
        }

        // Destroy the invisible window
        if (m_wndOwner.m_hWnd != NULL)
            m_wndOwner.DestroyWindow();

        return FALSE;
    }

    BOOL CInvDlgDlg::OnInitDialog()
    {
        // Normal MFC generated template code....

        // TODO: Add extra initialization here

        /* Remove the WS_EX_APPWINDOW style */
        ModifyStyleEx( WS_EX_APPWINDOW, 0 );

        return TRUE;
    }

    Now the dialog is displayed, you can Alt+Tab to it, but there's no
    button on the taskbar for it.

    Dave

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Tuesday, January 11, 2011 1:29 PM

All replies

  • >I have created an MFC Dialog based application. I don't want that application to be displayed in Taskbar, even if the window is VISIBL. How can I Prevent that?

    Create a normal MFC dialog application, and an invisible top level
    window before the dialog constructor. Pass the invisible window as the
    parent of the dialog and call DoModal.

    Modify the style of the dialog window in OnInitDialog to remove the
    WS_EX_APPWINDOW style.

    BOOL CInvDlgApp::InitInstance()
    {
        // Normal MFC generated code...

        // Doctored version of BekiM's stealth code

        // (m_wndOwner is a member CWnd I've added to
        // the application class)

        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;
        }

        CInvDlgDlg 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
        }

        // Destroy the invisible window
        if (m_wndOwner.m_hWnd != NULL)
            m_wndOwner.DestroyWindow();

        return FALSE;
    }

    BOOL CInvDlgDlg::OnInitDialog()
    {
        // Normal MFC generated template code....

        // TODO: Add extra initialization here

        /* Remove the WS_EX_APPWINDOW style */
        ModifyStyleEx( WS_EX_APPWINDOW, 0 );

        return TRUE;
    }

    Now the dialog is displayed, you can Alt+Tab to it, but there's no
    button on the taskbar for it.

    Dave

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Tuesday, January 11, 2011 1:29 PM
  • The easies way is using the WS_EX_TOOLWINDOW style. Than you have a toolwindow with a small caption.

    If you want a dialog with a normal dialog caption, than your dialog window has to be a child of a (invisible) ToolWindow.

    In my opinion a normal popup window should have a taskbar button.

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Tuesday, January 11, 2011 1:29 PM
  • You may want to consider making this a tray application as well.  This class makes it pretty simple to implement:

    http://www.naughter.com/ntray.html

    Tom

    • Marked as answer by maverick786us Friday, January 14, 2011 5:54 AM
    Wednesday, January 12, 2011 7:26 PM
  • In Dialog class OnInitDailog function add this code:

    ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE platform embedded development.
    • Marked as answer by maverick786us Friday, January 14, 2011 5:53 AM
    Thursday, January 13, 2011 6:02 AM