Click here to Skip to main content
15,913,296 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Embedding data in exe's Pin
Xzyx987X8-Jul-05 17:07
Xzyx987X8-Jul-05 17:07 
GeneralRe: Embedding data in exe's Pin
John R. Shaw8-Jul-05 18:33
John R. Shaw8-Jul-05 18:33 
GeneralRe: Embedding data in exe's Pin
David Crow8-Jul-05 16:36
David Crow8-Jul-05 16:36 
GeneralRe: Embedding data in exe's Pin
Xzyx987X8-Jul-05 17:09
Xzyx987X8-Jul-05 17:09 
Generalhelp: C++ copy constructors Pin
heskel8-Jul-05 15:04
heskel8-Jul-05 15:04 
GeneralRe: help: C++ copy constructors Pin
John R. Shaw8-Jul-05 16:01
John R. Shaw8-Jul-05 16:01 
Generalhelp:update_command_ui Pin
happycpp8-Jul-05 13:33
happycpp8-Jul-05 13:33 
GeneralRe: help:update_command_ui Pin
Jose Lamas Rios10-Jul-05 18:07
Jose Lamas Rios10-Jul-05 18:07 
MFC doesn't implement the automatic update of UI elements for dialog based apps.

If you want to have this functionality for a menu in a dialog based application you could do something like the following (it wasn't thoroughly tested and makes use of undocumented functions so, as always, use it at your own risk):

In you dialog class declaration, add the following member:

afx_msg void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);

In your dialog's cpp file, make the following changes (change "YourDialog" to the actual class name of your dialog too):

BEGIN_MESSAGE_MAP(YourDialog, CDialog)
   // what you already have
   // [...]
 
   // Add this:
   ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
 
void AFXAPI AfxCancelModes(HWND hWndRcvr);
 
void YourDialog::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
   AfxCancelModes(m_hWnd);
 
   if (bSysMenu)
      return;     // don't support system menu
 
   ENSURE_VALID(pMenu);
 
   // check the enabled state of various menu items
 
   CCmdUI state;
   state.m_pMenu = pMenu;
   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 == pMenu->m_hMenu)
      state.m_pParentMenu = pMenu;    // parent == child for tracking popup
   else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
   {
      CWnd* pParent = GetTopLevelParent();
         // 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 nItemIndex = 0; nItemIndex < nIndexMax; nItemIndex++)
         {
            if (::GetSubMenu(hParentMenu, nItemIndex) == pMenu->m_hMenu)
            {
               // when popup is found, m_pParentMenu is containing menu
               state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
               break;
            }
         }
      }
   }
 
   state.m_nIndexMax = pMenu->GetMenuItemCount();
   for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
      state.m_nIndex++)
   {
      state.m_nID = pMenu->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 = pMenu->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, FALSE);    // 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, state.m_nID < 0xF000);
      }
 
      // adjust for menu deletions and additions
      UINT nCount = pMenu->GetMenuItemCount();
      if (nCount < state.m_nIndexMax)
      {
         state.m_nIndex -= (state.m_nIndexMax - nCount);
         while (state.m_nIndex < nCount &&
            pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
         {
            state.m_nIndex++;
         }
      }
      state.m_nIndexMax = nCount;
   }
}


Hope that helps, and please let us know if it worked or not.


--
jlr
http://jlamas.blogspot.com/[^]
GeneralC++ Copy constructors Pin
heskel8-Jul-05 13:02
heskel8-Jul-05 13:02 
GeneralRe: C++ Copy constructors Pin
Kevin McFarlane8-Jul-05 13:07
Kevin McFarlane8-Jul-05 13:07 
GeneralRe: C++ Copy constructors Pin
heskel8-Jul-05 13:12
heskel8-Jul-05 13:12 
GeneralRe: C++ Copy constructors Pin
Nemanja Trifunovic8-Jul-05 14:06
Nemanja Trifunovic8-Jul-05 14:06 
Generalwin32 threads Pin
Ann668-Jul-05 12:20
sussAnn668-Jul-05 12:20 
GeneralRe: win32 threads Pin
Blake V. Miller8-Jul-05 16:29
Blake V. Miller8-Jul-05 16:29 
Generalto IE programmers Pin
llp00na8-Jul-05 8:08
llp00na8-Jul-05 8:08 
GeneralRe: to IE programmers Pin
Jose Lamas Rios8-Jul-05 10:47
Jose Lamas Rios8-Jul-05 10:47 
GeneralRe: to IE programmers Pin
Ravi Bhavnani8-Jul-05 11:40
professionalRavi Bhavnani8-Jul-05 11:40 
GeneralRe: to IE programmers Pin
ThatsAlok8-Jul-05 21:21
ThatsAlok8-Jul-05 21:21 
GeneralHelp with LookupAccountSid Pin
Dimitris Vikeloudas8-Jul-05 5:54
Dimitris Vikeloudas8-Jul-05 5:54 
GeneralRe: Help with LookupAccountSid Pin
David Crow8-Jul-05 6:07
David Crow8-Jul-05 6:07 
GeneralRe: Help with LookupAccountSid..still looking Pin
Dimitris Vikeloudas8-Jul-05 6:22
Dimitris Vikeloudas8-Jul-05 6:22 
GeneralRe: Help with LookupAccountSid..still looking Pin
David Crow8-Jul-05 8:11
David Crow8-Jul-05 8:11 
GeneralUnderstanding Debug Information Displayed Pin
jerry1211a8-Jul-05 5:28
jerry1211a8-Jul-05 5:28 
GeneralRe: Understanding Debug Information Displayed Pin
S. Senthil Kumar8-Jul-05 6:03
S. Senthil Kumar8-Jul-05 6:03 
GeneralRe: Understanding Debug Information Displayed Pin
Tom Archer8-Jul-05 6:56
Tom Archer8-Jul-05 6:56 

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.