• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            road420

            導航

            <2008年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統計

            常用鏈接

            留言簿(2)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            讓對話框對UPDATE_COMMAND_UI生效

             問題:一般情況下我們用UPDATE_COMMAND_UI來修改菜單的狀態(enable/disable, check/uncheck, change text),但這個方法在一個基于對話框上的菜單卻沒有效果。
            void CTestDlg::OnUpdateFileExit(CCmdUI* pCmdUI)
            {
                 pCmdUI->Enable(FALSE);
                 pCmdUI->SetCheck(TRUE);
                 pCmdUI->SetRadio(TRUE);
                 pCmdUI->SetText("Close");
            //以上方法在MDI、SDI程序中都能起作用,在對話框中卻沒有效果,根本沒有調用這個函數。
            }
             
            原因分析:當顯示一個下拉的菜單的時候,在顯示菜單前會發送WM_INITMENUPOPUP消息。而CFrameWnd::OnInitMenuPopup函數會刷新這個菜單項,同時如果有UPDATE_COMMAND_UI響應函數,則調用它。通過它來更新反應每個菜單的外觀效果(enabled/disabled, checked/unchecked).
            在一個基于對話框的程序中,因為沒有OnInitMenuPopup函數,所以不會調用UPDATE_COMMAND_UI響應函數,而是使用了CWnd類的默認處理, 這種處理沒有調用UPDATE_COMMAND_UI響應函數。

            解決方法如下:
            第一步:
            在對話框類的.cpp文件,添加一個ON_WM_INITMENUPOPUP入口到消息映射里面
            BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
            //}}AFX_MSG_MAP
            ON_WM_INITMENUPOPUP()
            END_MESSAGE_MAP()
            第二步:
            在對話框類的.h文件添加消息函數聲明。
            // Generated message map functions
            //{{AFX_MSG(CDisableDlgMenuDlg)
            afx_msg void OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu);
            //}}AFX_MSG
            DECLARE_MESSAGE_MAP()
            第三步:
            在對話框類的.cpp文件添加如下函數代碼(大部分代碼取自WinFrm.cpp文件的函數CFrameWnd::OnInitMenuPopup):
            void C******Dlg::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;
               }
            }

            posted on 2008-07-17 11:42 深邃者 閱讀(209) 評論(0)  編輯 收藏 引用

            7777久久久国产精品消防器材| 色综合久久天天综合| 亚洲午夜福利精品久久| 亚洲精品无码久久久| 99精品国产99久久久久久97| 日韩精品久久无码中文字幕| 亚洲狠狠综合久久| 婷婷久久五月天| 久久se精品一区二区| 少妇被又大又粗又爽毛片久久黑人| 久久天天躁狠狠躁夜夜不卡| 丰满少妇人妻久久久久久| 国产一区二区精品久久凹凸| 久久久久高潮综合影院| 久久精品国产亚洲一区二区| 欧美精品一区二区久久| 狠狠色丁香久久婷婷综| 久久人妻少妇嫩草AV蜜桃| 99久久亚洲综合精品网站| 久久久久亚洲精品无码蜜桃| 色婷婷久久综合中文久久一本| 97久久精品无码一区二区天美| 久久久久久久久久久久久久| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 精品水蜜桃久久久久久久| 亚洲中文久久精品无码ww16| 国产AV影片久久久久久| 精品久久久久久无码专区| 伊人色综合久久天天人守人婷| 久久精品中文字幕第23页| 国产精品久久影院| 国产精品毛片久久久久久久| 亚洲AV无码久久寂寞少妇| 欧美日韩久久中文字幕| 欧美激情精品久久久久久久| 天天做夜夜做久久做狠狠| 天堂无码久久综合东京热| 亚洲欧美成人久久综合中文网| 色天使久久综合网天天| 久久久久久久免费视频| 久久久久波多野结衣高潮|