CMenu m_myMenu; CMenu m_myPopMenu; VERIFY(m_myMenu.CreateMenu()); VERIFY(m_myPopMenu.CreatePopupMenu()); m_myPopMenu.AppendMenu(MF_STRING, ID_NEW_MENU1, (LPCTSTR)"&New1"); m_myPopMenu.InsertMenu(0,MF_BYCOMMAND,ID_NEW_MENU2,"&New2"); m_myPopMenu.InsertMenu(ID_NEW_MENU2,MF_BYCOMMAND,ID_NEW_MENU3,"&New3"); m_myMenu.AppendMenu(MF_POPUP, (UINT) m_myPopMenu.m_hMenu, "&MyMenu"); SetMenu(&m_myMenu); ( vspath 发表于 2004-6-1 11:30:00) 上面的操作,代码实际修改了资源文件*.rc中对话框的定义,修改如下(红色部分): IDD_TABORDER_DIALOG DIALOGEX 0, 0, 213, 162 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "TabOrder" MENU IDR_MENU_SELF //如果对话框有菜单,则只需如此声明就可以了,没有则去掉此行 FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "测试控件Tab Order顺序的调整:",IDC_STATIC,7,20,124,15 PUSHBUTTON "Button1",IDC_BUTTON1,7,41,59,17 PUSHBUTTON "取消",IDCANCEL,156,139,50,16 DEFPUSHBUTTON "确定",IDOK,101,139,50,16 EDITTEXT IDC_EDIT1,7,64,61,17,ES_AUTOHSCROLL CONTROL "选中1",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 7,91,58,14 END ( vspath 发表于 2004-6-1 10:15:00) //第三种方法 动态创建 CMenu m_menu; 提示: error C2039: 'Create' : is not a member of 'CMenu' ( lhongliangi 发表于 2004-2-9 10:54:00) 还有一些常用的: //第一种方法 CMenu m_menu; m_menu.LoadMenu(IDR_MENU);//菜单资源标识 SetMenu(&m_menu); //第二种方法 HMENU hMenu=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU)); ::SetMenu(this->m_hWnd,hMenu); //第三种方法 动态创建 CMenu m_menu; m_menu.Create(); m_menu.AppendMenu(...); m_menu.InsertMenu(...); SetMenu(&m_menu);