灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:4262回复:0

[二级考试]2013年计算机二级考试c++备考笔记2

楼主#
更多 发布于:2012-10-19 12:38

基本菜单操作  Pop-up0 Pop-up1 Pop-up2 Pop-up3 …

  0-0 1-0 2-0 3-0 …

  0-1 1-1 2-1 3-1 …

  0-2 1-2 2-2 3-2 …

  可以通过CWnd的成员函数GetMenu来获取指向菜单栏的指针,对菜单子项的访问可以通过菜单的索引标识来实现。

  操作一个菜单项的2种实例 www.examw.com

  1 GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_BYPOSITION | MF_CHECKED);

  2 GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_OPEN,MF_BYCOMMAND | MF_CHECKED);

  MSDN中关于MF_BYCOMMAND 和MF_BYPOSITION的解释

  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.

  GetSubMenu有很多成员函数,用于菜单的操作。中华考试网

  快捷菜单

  工程-添加到工程-Components and Controls,从这里可可以选择VC提供的一些组件和控件,添加一个POPUP MENU,选择所属于View类,此时View类中便添加了一个OnConTextMenu函数。

  01 void CMenuView::OnConTextMenu(CWnd*, CPoint point)

  02 {

  03 // CG: This block was added by the Pop-up Menu component

  04 {

  05 if (point.x == -1 ;; point.y == -1){

  06 //keystroke invocation

  07 CRect rect;

  08 GetClientRect(rect);

  09 ClientToScreen(rect);

  10 point = rect.TopLeft();

  11 point.Offset(5, 5);

  12 }

  13 CMenu menu;

  14 VERIFY(menu.LoadMenu(CG_IDR_POPUP_MENU_VIEW));

  15 CMenu* pPopup = menu.GetSubMenu(0);

  16 ASSERT(pPopup != NULL);

  17 CWnd* pWndPopupOwner = this;

  18 while (pWndPopupOwner->GetStyle() ; WS_CHILD)

  19 pWndPopupOwner = pWndPopupOwner->GetParent();

  20 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,

  21 pWndPopupOwner);

  22 }

  23 }

  运行之后,在View类区域右键,会出现一个弹出窗口。


喜欢0 评分0
游客

返回顶部