动态添加子菜单的菜单项响应函数

动态添加子菜单的菜单项响应函数:ON_COMMAND_RANGE  

孙鑫 第六章 phone

CMainFrame.h添加消息原型

//{{AFX_MSG(CMainFrame)

         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

                   // NOTE - the ClassWizard will add and remove member functions here.

                   //    DO NOT EDIT what you see in these blocks of generated code!

         //}}AFX_MSG

         afx_msg void OnDoSomething(UINT  nID);

         DECLARE_MESSAGE_MAP()

 

CMainFrame.app添加消息映射

BEGIN_MESSAGE_MAP(CMainFrame,   CFrameWnd)  
        //   ...    
        ON_COMMAND_RANGE(ID_START_FROM,   ID_END_AT,   OnDoSomething)  
  END_MESSAGE_MAP()

CMainFrame.app添加消息定义

void  CMainFrame::OnDoSomething(UINT   nID)  

{

         CPhoneView *pView = (CPhoneView *)GetActiveView();

         int meun_all = pView->m_strArray.GetSize();

         CClientDC dc(pView);

         switch (nID)

         {

         case IDM_PHONE1:

                   {

                            dc.TextOut(0,0,pView->m_strArray.GetAt(nID-IDM_PHONE1));

                   }  break;

         case IDM_PHONE1+1:

                   {

                            dc.TextOut(0,0,pView->m_strArray.GetAt(nID-IDM_PHONE1));

                   }  break;

         }

        

}

注意:头文件包含

#include    “phoneView.h”添加到CmainFrame.cpp前部

视类源文件中#include    “phoneDoc.h”剪切到phoneView.h文件前部

你可能感兴趣的:(command)