Click here to Skip to main content
15,881,204 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Nibu babu thomas31-Mar-08 21:22
Nibu babu thomas31-Mar-08 21:22 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti31-Mar-08 21:25
kutti31-Mar-08 21:25 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Nibu babu thomas31-Mar-08 21:29
Nibu babu thomas31-Mar-08 21:29 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti31-Mar-08 22:42
kutti31-Mar-08 22:42 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Nibu babu thomas31-Mar-08 22:54
Nibu babu thomas31-Mar-08 22:54 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti31-Mar-08 23:02
kutti31-Mar-08 23:02 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Nibu babu thomas31-Mar-08 23:14
Nibu babu thomas31-Mar-08 23:14 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Saurabh.Garg31-Mar-08 21:33
Saurabh.Garg31-Mar-08 21:33 
Read the link I sent you carefully.

You have to add a handler for ON_WM_INITMENUPOPUP and the add the following code in the handler. Only then command UI events will be called for a dialog box.

void CTestDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
    ASSERT(pPopupMenu != NULL);
    // Check the enabled state of various menu items.

    CCmdUI state;
    state.m_pMenu = pPopupMenu;
    ASSERT(state.m_pOther == NULL);
    ASSERT(state.m_pParentMenu == NULL);

    // Determine if menu is popup in top-level menu and set m_pOther to
    // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
    HMENU hParentMenu;
    if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
        state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
    else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
    {
        CWnd* pParent = this;
           // Child windows don't have menus--need to go to the top!
        if (pParent != NULL &&
           (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
        {
           int nIndexMax = ::GetMenuItemCount(hParentMenu);
           for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
           {
            if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
            {
                // When popup is found, m_pParentMenu is containing menu.
                state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
                break;
            }
           }
        }
    }

    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
    for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
      state.m_nIndex++)
    {
        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
        if (state.m_nID == 0)
           continue; // Menu separator or invalid cmd - ignore it.

        ASSERT(state.m_pOther == NULL);
        ASSERT(state.m_pMenu != NULL);
        if (state.m_nID == (UINT)-1)
        {
           // Possibly a popup menu, route to first item of that popup.
           state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
           if (state.m_pSubMenu == NULL ||
            (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
            state.m_nID == (UINT)-1)
           {
            continue;       // First item of popup can't be routed to.
           }
           state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
        }
        else
        {
           // Normal menu item.
           // Auto enable/disable if frame window has m_bAutoMenuEnable
           // set and command is _not_ a system command.
           state.m_pSubMenu = NULL;
           state.DoUpdate(this, FALSE);
        }

        // Adjust for menu deletions and additions.
        UINT nCount = pPopupMenu->GetMenuItemCount();
        if (nCount < state.m_nIndexMax)
        {
           state.m_nIndex -= (state.m_nIndexMax - nCount);
           while (state.m_nIndex < nCount &&
            pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
           {
            state.m_nIndex++;
           }
        }
        state.m_nIndexMax = nCount;
    }
}


-Saurabh
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti31-Mar-08 21:35
kutti31-Mar-08 21:35 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Saurabh.Garg31-Mar-08 22:48
Saurabh.Garg31-Mar-08 22:48 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti31-Mar-08 22:54
kutti31-Mar-08 22:54 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Saurabh.Garg31-Mar-08 23:23
Saurabh.Garg31-Mar-08 23:23 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti1-Apr-08 2:25
kutti1-Apr-08 2:25 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Saurabh.Garg1-Apr-08 4:07
Saurabh.Garg1-Apr-08 4:07 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti8-Apr-08 1:48
kutti8-Apr-08 1:48 
QuestionRe: check/ uncheck menu item in a pop up menu Pin
David Crow1-Apr-08 3:41
David Crow1-Apr-08 3:41 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
Hamid_RT7-Apr-08 2:57
Hamid_RT7-Apr-08 2:57 
GeneralRe: check/ uncheck menu item in a pop up menu Pin
kutti7-Apr-08 18:12
kutti7-Apr-08 18:12 
GeneralConnecting SQL Server DB in C++/VC++ Pin
Sgg24531-Mar-08 19:58
Sgg24531-Mar-08 19:58 
QuestionRe: Connecting SQL Server DB in C++/VC++ Pin
CPallini31-Mar-08 21:47
mveCPallini31-Mar-08 21:47 
QuestionRe: Connecting SQL Server DB in C++/VC++ Pin
David Crow1-Apr-08 3:43
David Crow1-Apr-08 3:43 
GeneralRe: Connecting SQL Server DB in C++/VC++ Pin
Hamid_RT7-Apr-08 2:56
Hamid_RT7-Apr-08 2:56 
Questionclosing and reopening exploere.exe using win32 or anyother language Pin
Jach Mullan31-Mar-08 19:53
Jach Mullan31-Mar-08 19:53 
GeneralRe: closing and reopening exploere.exe using win32 or anyother language Pin
Nibu babu thomas31-Mar-08 20:48
Nibu babu thomas31-Mar-08 20:48 
Questionhiding the taskbar icons using win32 Pin
Jach Mullan31-Mar-08 19:50
Jach Mullan31-Mar-08 19:50 

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.