05菜单编程_静态添加.docVIP

  • 4
  • 0
  • 约 15页
  • 2016-11-27 发布于河南
  • 举报
05菜单编程_静态添加

菜单编程_静态添加 1.新建工程 新建一个MFC单文档应用程序,取名Menu 在IDM_NAINFRAME中添加一个菜单test -右键- ClassWizard… 分别在CMainFrame、CMenuDoc、CMenuApp、CMenuView中添加对Test菜单项的COMMAND消息。 MessageBox(ManinFrame clicked); AfxMessageBox(Doc clicked); AfxMessageBox(App clicked); MessageBox(clicked); 命令消息传递顺序:view类-doc类-frame类-app类 2. 消息的分类(如下图) 创建标记菜单: 在新建菜单上创建一个标记菜单,在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数中添加: // GetMenu()-GetSubMenu(0)-CheckMenuItem(0,MF_BYPOSITION|MF_CHECKED);//添加标记 GetMenu()-GetSubMenu(0)-CheckMenuItem(ID_FILE_NEW,MF_BYCOMMAND|MF_CHECKED);//添加标记第二种方法 注释: UINT CheckMenuItem( UINT nIDCheckItem, UINT nCheck ); Return Value The previous state of the item: MF_CHECKED or MF_UNCHECKED, or 0xFFFFFFFF if the menu item did not exist. Parameters nIDCheckItem Specifies the menu item to be checked, as determined by nCheck. nCheck Specifies how to check the menu item and how to determine the item’s position in the menu. The nCheck parameter can be a combination of MF_CHECKED or MF_UNCHECKED with MF_BYPOSITION or MF_BYCOMMAND flags. These flags can be combined by using the bitwise OR operator. They have the following meanings: MF_BYCOMMAND???Specifies that the parameter gives the command ID of the existing menu item. This is the default. MF_BYPOSITION???Specifies that the parameter gives the position of the existing menu item. The first item is at position 0. MF_CHECKED???Acts as a toggle with MF_UNCHECKED to place the default check mark next to the item. MF_UNCHECKED???Acts as a toggle with MF_CHECKED to remove a check mark next to the item. Remarks Adds check marks to or removes check marks from menu items in the pop-up menu. The nIDCheckItem parameter specifies the item to be modified. The nIDCheckItem parameter may identify a pop-up menu item as well as a menu item. No special steps are required to check a pop-up menu item. Top-level menu items cannot be checked. A pop-up menu item must be checked by position since it does not have a menu-item identifier associated with i

文档评论(0)

1亿VIP精品文档

相关文档