Updating menu items in dialog-based apps: Solution 
Author Message
 Updating menu items in dialog-based apps: Solution

This is sorta an answer to my own posted questions on menus in dialog
boxes.

The issue is how to use functions created/mapped by Class Wizard to
ON_COMMAND_UI messages in a dialog-based app. Normally, they don't
wrok, as they're usually handled by CFrameWnd, which a dialog app

gave a clue, and this is my formulation of it. It's just a re-hash of
what Kenneth posted, but formulated into nice files you can add to
future project easily. Hopes this helps some one else, and thanks to
Kenneth for the pointer.

- Randy Langer

--------------------------------------------------------------------

    /* DialogMenuUpdate.h */

#if !defined(DIALOGMENUUPDATE_H__)
#define DIALOGMENUUPDATE_H__

/********************************************************************

This function is used to use the ON_COMMAND_UI command mappings in
dialog-based apps. Normally these won't work for a dialog app, since
they're normally hannled by CFrameWnd, which a dialog-based app lacks.
You can, however, use these Class Wizard created mappings (which shows
up in the CWinApp based class, not the dialog class), by the following
method:

1. Use Class Wizard to map ON_COMMAND_UI for menu items in the usual
fashion. Note that they're mapped to the CWinApp-based class, not the
dialog class.

2. In the dialog class, add ON_WM_INITMENUPOPUP() to the message map
list, *OUTSIDE* of the "{{AFX_MSG_MAP(CVersDlg)" block (sorry, Class
Wizard won't do this for you).

3. Add the following function to the dialog header file:

    void    OnInitMenuPopup(CMenu *, UINT, BOOL);

4. Add the following function to the dialog implementation (.cpp)
file:

    void CYourDlg::OnInitMenuPopup(CMenu *a, UINT b, BOOL c)
    {

        DialogMenuUpdate(this, a, b, c);
        CDialog::OnInitMenuPopup(a, b, c);
    }

(using the correct class name for 'CYourDlg', of course). Also,
#include this header file you're reading to the dialog class
implementation file.

5. Add 'DialogMenuUpdate.cpp' to your project.

********************************************************************/

void    DialogMenuUpdate(CWnd *, CMenu *, UINT, BOOL);

#endif

--------------------------------------------------------------------

    /* DialogMenuUpdate.cpp */

#include    "stdafx.h"
#include    "DialogMenuUpdate.h"

void
DialogMenuUpdate(CWnd *p, CMenu *y, UINT, BOOL sysCmd)
{

    if(sysCmd)
        return;

CCmdUI  q;

    ASSERT(y != NULL);

    q.m_pMenu = y;
    ASSERT(q.m_pOther == NULL);

    q.m_nIndexMax = y->GetMenuItemCount();

    for(q.m_nIndex = 0; q.m_nIndex < q.m_nIndexMax; q.m_nIndex++)
    {
        if(q.m_nID = y->GetMenuItemID(q.m_nIndex))
        {
            ASSERT(q.m_pOther == NULL);
            ASSERT(q.m_pMenu != NULL);

            if(q.m_nID == (UINT) -1)
            {
                q.m_pSubMenu = y->GetSubMenu(q.m_nIndex);

                if(q.m_pSubMenu &&
                    (q.m_nID = q.m_pSubMenu->GetMenuItemID(0)) &&
                    q.m_nID != (UINT) -1)
                        q.DoUpdate(p, FALSE);
            }
            else
            {
                q.m_pSubMenu = NULL;
                q.DoUpdate(p, q.m_nID < 0xF000);
            }
        }
    }

Quote:
}

--- End of post ---------------------------------------------------


Thu, 15 Jul 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Checking menu items in dialog based app.

2. Disabling main menu items in MFC based apps

3. Updating dialog based application menu status

4. update menu based on dialog resopnse

5. Dialog Based & Menu Update :: MFC

6. How to check a menu item in a dialog based application

7. Updating dialog based application menu status

8. Checking Menu Items in Dialog Based Application

9. Problem updating Menu state with Dialog-based application

10. Q: Set Check Mark in Menu Item In Based Dialog Application

11. Checked menu items in a dialog based application

12. Updating the Taskbar from a dialog based app

 

 
Powered by phpBB® Forum Software