各位:我现在想在CReBar上设置CMenu,调用CReBar::SetMenu(...)为什么会不行?正确的做法应该是怎样的?



    * CSDN首页
    * 新 闻
    * 社 区
    * 文 档
    * Blog
    * 杂 志
    * .NET
    * Java
    * 移动
    * 游戏
    * 管理
    * 招聘
    * 培训
    * 搜 索
    * 代码
    * 第二书店
    * 博文视点

CSDN社区
CSDN社区  -  VC/MFC / 基础类
收藏此页 |  打印 |  关闭窗口
主题关键词

    * menu
    * button
    * 菜单
    * hot-tracking
    * toolbar

    * key
    * bar
    * display
    * navigation
    * when

得分解答快速导航

    * 帖主:ookaiii
    * 111222
    * jifeng

相关连接

    * Visual C++/MFC FAQ
    * C/C++ Blog
    * Visual C++类图书
    * Visual C++类源码下载

广告也精彩
反馈

请通过下述方式给我们反馈.
反馈

Valid XHTML 1.0 Strict Valid CSS!
各位:我现在想在CReBar上设置CMenu,调用CReBar::SetMenu(...)为什么会不行?正确的做法应该是怎样的?
ookaiii (IUnknown* pIWorld)  三级用户 该版得分小于等于1000分,大于500分   2001-04-30 01:29:00 在 VC/MFC / 基础类 提问

各位:我现在想在CReBar上设置CMenu,调用CReBar::SetMenu(...)为什么会不行?正确的做法应该是怎样的?另:这种情况也同样发生在CButton等上,好像只有CFrameWnd调用SetMenu才没有问题,我想问的式为什么会这样? 
  
 
问题点数:20、回复次数:70
1楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 01:36:00  得分 0

强烈关注!!!!!!!!!我要是会就我也不会这个!!
Top
2楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 01:38:00  得分 0

上面输入法出毛病了,语句不通啊,就是说,我也不会这个
Top
3楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 01:53:00  得分 0

我想了好长时间也不懂,111222叫个朋友怎么样,我很瓦哦
Top
4楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 01:59:00  得分 0

我也想了好长时间,用各种MenuBar都不理想... 
 
Top
5楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:08:00  得分 0

好像就我们两个人在这里唧唧歪歪,每人帮么?我很心焦
Top
6楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:08:00  得分 0

我试了setmenu     不好使啊
Top
7楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:09:00  得分 0

CReBar是从CWnd继承而来的啊,为什么setmenu不好使呢? 
  MSDN上没有讲解如何把菜单加进ReBar
Top
8楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:12:00  得分 0

你看MSDN里面CReBar的最初介绍页面,就是介绍继承关系的那个 
  上面的菜单好象是按钮啊
Top
9楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:13:00  得分 0

你还在吗? 
 
Top
10楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:14:00  得分 0

调试器会吧你带到CWnd::SetMenu(..)处 
  是ASSERT(IsWindow(m_hWnd))处的错,可我感觉CReBar的窗口有了啊,我不明白
Top
11楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:15:00  得分 0

我在
Top
12楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:17:00  得分 0

好象只有CWnd才能塞进ReBar
Top
13楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:17:00  得分 0

等我传一个图片到网上你看
Top
14楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:18:00  得分 0

好啊
Top
15楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:20:00  得分 0

我先做成gif
Top
16楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:20:00  得分 0

你放哪?
Top
17楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:23:00  得分 0

http://61.129.70.31/103180161/jeffreyren/111222/rebar.jpg 
  
  你看看上面的菜单
Top
18楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:24:00  得分 0

上面的菜单到底是怎么弄的? 
  你说IE的菜单又是怎么弄的呢? 
  左边有一个Gripper   bar(就是那个竖条,能通过它拉动REBAR)
Top
19楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:25:00  得分 0

有人说:“IE的菜单是一堆按钮,点上去的时候TrackPopupMenu....” 
  难道MS的东西也要这么费劲么? 
  
 
Top
20楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:27:00  得分 0

还在么?你几分钟刷新一次这个页面?
Top
21楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:27:00  得分 0

AddBar这个函数也用不了,这个只针对CWnd啊 
  Menu是CObject继承而来的...
Top
22楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:29:00  得分 0

我刚才试了这个 
  
  CMenu   m_menu; 
  m_menu.LoadMenu(IDR_MAINFRAME); 
  m_wndReBar.Create(this); 
  m_wndReBar.SetMenu(&m_menu); 
  
  
  没有效果
Top
23楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:30:00  得分 0

嘿嘿,从msdn上抄的吧,不过用spy+看他们都是由toolwindow(好像是,不清了)你看看 
  还有要想给工具跳加背景该怎么办
Top
24楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:31:00  得分 0

对不起,我正和朋友聊,没忙过来
Top
25楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:32:00  得分 0

工具条加背景很容易啊
Top
26楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:32:00  得分 0

CMenu   m_menu; 
  m_menu.LoadMenu(IDR_MAINFRAME); 
  m_wndReBar.Create(this); 
  m_wndReBar.SetMenu(&m_menu); 
  m_menu.Detach(); 
  我也是过的,的确没任何效果 
 
Top
27楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:34:00  得分 0

m_wndReBar.AddBar(&m_wndToolBar.... 
  
  
  BOOL   AddBar(   CWnd*   pBar,   LPCTSTR   lpszText   =   NULL,   CBitmap*   pbmp   =   NULL,   DWORD   dwStyle   =   RBBS_GRIPPERALWAYS   |   RBBS_FIXEDBMP   ); 
  
  
  这个函数就可以了
Top
28楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:34:00  得分 0

工具条加背景很容易啊   ?说说看,我想知道的,大哥
Top
29楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:34:00  得分 0

谢谢,
Top
30楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:37:00  得分 0

这个问题其实你也可以从别的从CWnd派生的class中看到,比如一些控制CButton,CStatic
Top
31楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:39:00  得分 10

CBitmap   bmp; 
  bmp.LoadBitmap(IDC_BK); 
  m_wndReBar.AddBar(&m_wndToolBar,NULL,&bmp,RBBS_GRIPPERALWAYS   ¦   RBBS_FIXEDBMP   ); 
  
  
  这就可以啦
Top
32楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:40:00  得分 0

为什么会不行?另外不知你有没有用spy++看过超级结巴,它的menu就是达到了这种效果
Top
33楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:41:00  得分 0

怎样才能利用REBAR实现IE那样的菜单呢?唉,我想了好久好久了(4、5天了!!)
Top
34楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:41:00  得分 0

我没有超级结巴啊
Top
35楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:42:00  得分 0

等我找点东东给你看
Top
36楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:44:00  得分 0

 回复人:gameboy999(无名) (2001-4-27   21:20:00)     得0分   
  好多模拟都是用toobar或你所说的ccomnadbar 
  用的方法都是点击按钮后弹出菜单(popup-style) 
  我怕麻烦,所以我也不会     
 
Top
37楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:46:00  得分 0

好的,我想能从原理上给各解答才是我最期望的,大家都不要看看就走啊,给点提示吧,我可是在乞讨了,求你给点知识吧
Top
38楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:47:00  得分 0

哪有大家啊,就我们两个人在的
Top
39楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:50:00  得分 0

哎,见死不救,行侠仗义的大侠都拿去了?观者就没有同情心?哪怕说的不对也被关系,一起提高吗!
Top
40楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:54:00  得分 0

世风日下,世态炎凉,没人施舍我就要饿死了 
 
Top
41楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:54:00  得分 0

三更半夜的,大家都在睡觉吧
Top
42楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:55:00  得分 0

看来只有TrackPopupMenu了,不过这种方法未免太笨了
Top
43楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 02:57:00  得分 0

你有没有什么办法让工具栏只显示文字(别说把图画成文字)
Top
44楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:57:00  得分 0

是的,但一定有人会的(毕竟有这样的范例),我们等等吧
Top
45楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 02:59:00  得分 0

看看msdn中有没有什么style,别的我没辙了
Top
46楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:03:00  得分 0

████         █             ██       █             █   ███             █           █ 
        █               █         █         █   █           █     █         █         █           █ 
        █               █         █         █   █           █     █                     █           
        █               █         █         █   █           █     ██                 █ 
        █               █         █         █     █         █     █                     █ 
        █               █         █         █     █       █       █         █         █ 
  ████         ███     ██           ██           ███               ████   
Top
47楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:05:00  得分 0

void   CMainFrame::OnDropDown(NMHDR*   pNotifyStruct,   LRESULT*   pResult) 
  { 
  //   this   function   handles   the   dropdown   menus   from   the   toolbar 
  NMTOOLBAR*   pNMToolBar   =   (NMTOOLBAR*)pNotifyStruct; 
  CRect   rect; 
  
  //   translate   the   current   toolbar   item   rectangle   into   screen   coordinates 
  //   so   that   we'll   know   where   to   pop   up   the   menu 
  m_wndToolBar.GetToolBarCtrl().GetRect(pNMToolBar->iItem,   &rect); 
  rect.top   =   rect.bottom; 
  ::ClientToScreen(pNMToolBar->hdr.hwndFrom,   &rect.TopLeft()); 
  if(pNMToolBar->iItem   ==   ID_FONT_DROPDOWN) 
  { 
  CMenu   menu; 
  CMenu*   pPopup; 
  
  //   the   font   popup   is   stored   in   a   resource 
  menu.LoadMenu(IDR_FONT_POPUP); 
  pPopup   =   menu.GetSubMenu(0); 
  pPopup->TrackPopupMenu(TPM_LEFTALIGN   |   TPM_LEFTBUTTON,   rect.left,   rect.top   +   1,   AfxGetMainWnd()); 
  } 
  
  *pResult   =   TBDDRET_DEFAULT; 
  }
Top
48楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:08:00  得分 0

 
  ████         █             ██       █             █   ███             █           █ 
          █                 █           █           █     █             █       █         █         █           █ 
          █                 █           █           █     █             █       █                     █   
          █                 █           █           █     █             █       ██                 █ 
          █                 █           █           █       █           █       █                     █ 
          █                 █           █           █       █         █         █         █         █ 
  ████         ███     ██           ██           ███               ████     
 
Top
49楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 03:11:00  得分 0

什么14?能说说么?我不明白
Top
50楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 03:13:00  得分 0

████         █             ██     █             █   ███             █         █ 
          █                 █         █         █     █             █     █         █         █         █ 
          █                 █         █         █     █             █     █                     █   
          █                 █         █         █     █             █     ██                 █ 
          █                 █         █         █     █         █     █                     █ 
          █                 █         █         █     █         █         █         █         █ 
  ████         ███     ██         ██         ███             ████     
  也看不明白,(知道我是多么的菜了吧)
Top
51楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:14:00  得分 0

上面是faint++的代码,你没学过,当然看不明白
Top
52楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:15:00  得分 0

faint++实现这种菜单很容易的、、听说faint#要出来了
Top
53楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 03:17:00  得分 0

什么是faint++?你给的代码看来是准备TrackPopupMenu了,那可不是办法啊, 
  要是真没人解答我就给你分了(最多等到后天),反正我都拿出来了,总不能收回去吧
Top
54楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 03:19:00  得分 0

哎,我很菜啊,不知道faint++,不知你学过com没有,
Top
55楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-04-30 03:23:00  得分 0

我得走了111222,很高兴和你聊,真期望明天就有解答,886
Top
56楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 03:26:00  得分 0

再见!
Top
57楼    () 一级用户 该版得分小于等于100分  回复于 2001-04-30 16:07:00  得分 0

我有例子,自己写一个menu类(继承Ctoolbar,改别人的)
Top
58楼  lolin   (lolin) 一级用户 该版得分小于等于100分  回复于 2001-04-30 16:29:00  得分 0

首先声明一个CDialogBar的派生类: 
  定义函数BOOL   Create(CWnd*   pParentWnd,   LPTSTR   nIDTemplate,   UINT   nStyle,   UINT    nID   );  //重要 
  
  class   MyDia   :   public   CDialogBar 
  { 
  //   Construction 
  public: 
  BOOL   Create(CWnd*   pParentWnd,   LPTSTR   nIDTemplate,   UINT   nStyle,   UINT   nID   ); 
  MyDia(CWnd*   pParent   =   NULL);       //   standard   constructor 
  
  //   Dialog   Data 
  //{{AFX_DATA(MyDia) 
  enum   {   IDD   =   IDR_TEST_MAINFRAME   }; 
  //   NOTE:   the   ClassWizard   will   add   data   members   here 
  //}}AFX_DATA 
  
  
  //   Overrides 
  //   ClassWizard   generated   virtual   function   overrides 
  //{{AFX_VIRTUAL(MyDia) 
  public: 
  virtual   void   DoDataExchange(CDataExchange*   pDX);         //   DDX/DDV   support 
  virtual   BOOL   PreCreateWindow(CREATESTRUCT&   cs); 
  //}}AFX_VIRTUAL 
  
  //   Implementation 
  protected: 
  
  //   Generated   message   map   functions 
  //{{AFX_MSG(MyDia) 
  afx_msg   int   OnCreate(LPCREATESTRUCT   lpCreateStruct); 
  //}}AFX_MSG 
  DECLARE_MESSAGE_MAP() 
  }; 
  
  向下面这样来实现Create函数: 
  m_dwStyle   =   (nStyle   &   CBRS_ALL); 
  CREATESTRUCT   cs; 
  memset(&cs,   0,   sizeof(cs)); 
  cs.lpszClass   =   _afxWndControlBar; 
  cs.style   =   (DWORD)nStyle   |   WS_CHILD; 
  cs.hMenu   =   (HMENU)nID; 
  cs.hInstance   =   AfxGetInstanceHandle(); 
  cs.hwndParent   =   pParentWnd->GetSafeHwnd(); 
  
  //   create   a   modeless   dialog 
  
  m_lpszTemplateName   =   lpszTemplateName; 
  
  //   initialize   common   controls 
  VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG)); 
  AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG); 
  
  BOOL   bSuccess   =   CreateDlg(lpszTemplateName,   pParentWnd); 
  
  m_lpszTemplateName   =   NULL; 
  
  if   (!bSuccess) 
  return   FALSE; 
  
  //   dialog   template   MUST   specify   that   the   dialog 
  //     is   an   invisible   child   window 
  SetDlgCtrlID(nID); 
  CRect   rect; 
  GetWindowRect(&rect); 
  m_sizeDefault   =   rect.Size();         //   set   fixed   size 
  
  //   force   WS_CLIPSIBLINGS 
  ModifyStyle(0,   WS_CLIPSIBLINGS); 
  
  if   (!ExecuteDlgInit(lpszTemplateName)) 
  return   FALSE; 
  
  //   force   the   size   to   zero   -   resizing   bar   will   occur   later 
  SetWindowPos(NULL,   0,   0,   0,   0,     SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW); 
  
  return   TRUE; 
  } 
  
  在将CReBar的WM_CHILD的属性改掉 
  注意:在CMainFrame中现在引用MyDia的实例。 
  CMainFrame::OnCreate中的 
  if   (!m_wndDlgBar.Create(this,   IDR_TEST_MAINFRAME,   
  CBRS_ALIGN_TOP,   AFX_IDW_DIALOGBAR)) 
  { 
  TRACE0("Failed   to   create   dialogbar/n"); 
  return   -1; //   fail   to   create 
  } 
  
  改为: 
  
  if   (!m_wndDlgBar.Create(this,   MAKEINTRESOURCE(IDR_TEST_MAINFRAME),   
  CBRS_ALIGN_TOP,   AFX_IDW_DIALOGBAR)) 
  { 
  TRACE0("Failed   to   create   dialogbar/n"); 
  return   -1; //   fail   to   create 
  } 
  测试通过。 
  
  这样做有什么负作用我也不知道! 
 
Top
59楼  lolin   (lolin) 一级用户 该版得分小于等于100分  回复于 2001-04-30 16:32:00  得分 0

说漏了一点: 
  在MyDia.ccp中加入如下头文件申明(注意顺须): 
  
  const   TCHAR   _afxWndControlBar[]   =   "MYTEST"; 
  #include   "D:/VC6.0/VC98/MFC/SRC/AFXIMPL.H" 
  #include   "MyDia.h" 
 
Top
60楼  lolin   (lolin) 一级用户 该版得分小于等于100分  回复于 2001-04-30 16:49:00  得分 0

对不起,原来是要在ReBar上创建CMenu!(好在效果差不多)。 
  你最好别要CToolBar了!
Top
61楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 20:41:00  得分 0

baiqian,有例子你给我俩看看啊! 
  lolin,我试试你的!!
Top
62楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 21:10:00  得分 0

Create函数里的m_dwStyle   是什么东西?怎样声明的?
Top
63楼  jifeng   (疾风) 二级用户 该版得分小于等于500分,大于100分  回复于 2001-04-30 21:21:00  得分 0

我看过MSDN上有篇文章,讲的是作IE风格的MenuBar,就是用Toolbar+TrackPopupMenu 
  还用到了Hook,太麻烦了 
  
 
Top
64楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 21:22:00  得分 0

jifeng: 
          哪有那篇文章?快给我看看!!!!
Top
65楼  111222   (www.111222.cn) 二星用户 该版得分小于等于30000分,大于10000分  回复于 2001-04-30 21:23:00  得分 0

jifeng;     
          主,我都卡在这里N天了!我眼睛都绿了!
Top
66楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-05-01 00:56:00  得分 0

没人解答么?
Top
67楼  jifeng   (疾风) 二级用户 该版得分小于等于500分,大于100分  回复于 2001-05-01 19:52:00  得分 0

D:/DL/msdn.microsoft.com/library/psdk/shellcc/CommCtls/FAQ/iemenubar.htm
Top
68楼  jifeng   (疾风) 二级用户 该版得分小于等于500分,大于100分  回复于 2001-05-01 19:53:00  得分 10

Creating   an   Internet   Explorer-style   Menu   Bar 
  At   a   glance,   the   Microsoft®   Internet   Explorer   5   menu   bar   looks   much   like   a   standard   menu.   However,   it   looks   quite   different   in   use.   The   following   illustration   shows   the   Internet   Explorer   menu   bar   with   the   Tools   item   selected. 
  
    
  The   menu   bar   is   actually   a   toolbar   control   that   looks   and   functions   very   much   like   a   standard   menu.   Instead   of   top-level   menu   items,   a   menu   bar   has   a   series   of   text-only   buttons   that   display   a   drop-down   menu   when   clicked.   However,   as   a   specialized   type   of   toolbar,   a   menu   bar   has   some   capabilities   that   standard   menus   lack.   As   a   toolbar   control: 
  
  It   can   be   customized   using   standard   toolbar   techniques,   allowing   the   user   to   move,   delete,   or   add   items.   
  It   can   have   hot-tracking,   so   that   users   will   know   when   they   are   over   a   top-level   item   without   having   to   click   it   first.   
  A   menu   bar   can   be   incorporated   into   a   rebar   control,   giving   it   the   following   features: 
  
  It   can   have   a   gripper,   which   allows   the   user   to   move   or   resize   the   band.   
  It   can   share   a   strip   in   the   rebar   control   with   other   bands,   such   as   the   standard   toolbar   in   the   preceding   illustration.   
  It   can   display   a   chevron   when   it   is   covered   by   an   adjacent   band,   giving   the   user   access   to   the   hidden   items.   
  It   can   have   an   application-defined   background   bitmap.   
  This   document   discusses   how   to   implement   a   menu   bar.   Since   a   menu   bar   is   a   specialized   implementation   of   a   toolbar   control,   the   focus   will   be   on   topics   that   are   specific   to   menu   bars.   For   a   discussion   of   how   to   incorporate   a   toolbar   into   a   rebar   control,   see   Creating   an   Internet   Explorer-style   Toolbar   and   Rebar   Controls. 
  
  Making   a   Toolbar   into   a   Menu   Bar   
  Handling   Navigation   with   Menu   Hot-Tracking   Disabled   
  Handling   Navigation   with   Menu   Hot-Tracking   Enabled   
  Making   a   Toolbar   into   a   Menu   Bar 
  To   make   a   toolbar   into   a   menu   bar: 
  
  Create   a   flat   toolbar   by   including   TBSTYLE_FLAT   with   the   other   window   style   flags.   The   TBSTYLE_FLAT   style   also   enables   hot-tracking.   With   this   style,   the   menu   bar   looks   much   like   a   standard   menu   until   the   user   activates   a   button.   Then,   the   button   appears   to   stand   out   from   the   toolbar   and   depress   when   it   is   clicked,   just   like   a   standard   button.   Because   hot-tracking   is   enabled,   all   that   is   needed   to   activate   a   button   is   for   the   cursor   to   hover   over   it.   If   the   cursor   moves   to   another   button,   it   will   be   activated   and   the   old   button   deactivated.   
  Create   list-style   buttons   by   including   TBSTYLE_LIST   with   the   other   window   style   flags.   This   style   creates   a   thinner   button   that   looks   more   like   a   standard   top-level   menu   item.   
  Make   the   buttons   text-only   by   setting   the   iBitmap   member   of   the   button's   TBBUTTON   structure   to   I_IMAGENONE   and   the   iString   member   to   the   button   text.   
  Give   each   button   the   BTNS_DROPDOWN   style.   When   the   button   is   clicked,   the   toolbar   control   sends   your   application   a   TBN_DROPDOWN   notification   to   prompt   it   to   display   the   button's   menu.   
  Incorporate   the   menu   bar   into   a   rebar   band.   Enable   both   grippers   and   chevrons,   as   discussed   in   Creating   an   Internet   Explorer-style   Toolbar.   
  Implement   a   TBN_DROPDOWN   handler   to   display   the   button's   drop-down   menu   when   it   is   clicked.   The   drop-down   menu   is   a   type   of   pop-up   menu.   It   is   created   with   TrackPopupMenu,   with   its   upper-left   corner   aligned   with   the   lower-left   corner   of   the   button.   
  Implement   keyboard   navigation,   so   that   the   menu   bar   is   fully   accessible   without   a   mouse.   
  Implement   menu   hot-tracking.   With   standard   menus,   once   a   top   level   menu   item's   menu   has   been   displayed,   moving   the   cursor   over   another   top-level   item   automatically   displays   its   menu   and   collapses   the   menu   of   the   previous   item.   The   toolbar   control   will   hot-track   the   cursor   and   change   the   button   image,   but   it   does   automatically   display   the   new   menu.   Your   application   must   do   so   explicitly.   
  Most   of   these   items   are   straightforward   to   implement   and   are   discussed   elsewhere.   See   Creating   an   Internet   Explorer-style   Toolbar,   Toolbar   Controls,   or   Rebar   Controls   for   a   general   discussion   of   how   to   use   toolbars   and   rebar   controls.   See   Menus   for   a   discussion   of   how   to   handle   pop-up   menus.   The   final   two   items,   keyboard   navigation   and   menu   hot-tracking,   are   discussed   in   the   remainder   of   this   document.   
  
  Handling   Navigation   with   Menu   Hot-Tracking   Disabled 
  Users   can   choose   to   navigate   the   menu   bar   with   the   mouse,   the   keyboard,   or   a   mixture   of   both.   To   implement   menu   bar   navigation,   your   application   needs   to   handle   toolbar   notifications   and   monitor   the   mouse   and   keyboard.   This   task   can   be   broken   into   two   distinct   parts:   with   and   without   menu   hot-tracking.   This   section   discusses   how   to   handle   navigation   when   no   menus   are   displayed   and   menu   hot-tracking   is   not   enabled. 
  
  Mouse   Navigation 
  If   menu   hot-tracking   is   disabled,   you   can   treat   a   menu   bar   as   a   normal   toolbar.   If   the   user   is   navigating   with   a   mouse,   all   your   application   needs   to   do   is   handle   the   TBN_DROPDOWN   notification.   When   this   notification   is   received,   display   the   appropriate   drop-down   menu,   and   enable   menu   hot-tracking.   From   then   on,   you   are   in   the   menu   hot-tracking   regime,   discussed   in   Implementing   Menu   Hot-Tracking. 
  
  As   discussed   in   Mixed   Navigation,   you   also   need   to   handle   the   TBN_HOTITEMCHANGE   notification   to   keep   track   of   the   active   button.   This   notification   is   irrelevant   if   the   user   is   only   navigating   with   the   mouse,   but   it   is   necessary   when   mouse   and   keyboard   navigation   are   mixed. 
  
  Keyboard   Navigation 
  As   noted   in   the   previous   section,   the   user   can   do   a   number   of   navigation   operations   with   the   keyboard   when   menu   hot-tracking   is   disabled.   Toolbar   controls   support   keyboard   navigation   only   if   they   have   focus.   They   also   do   not   handle   all   the   key   presses   that   are   needed   for   menu   bars.   The   simplest   solution   to   handling   keyboard   navigation   is   to   process   the   relevant   key   press   events   explicitly. 
  
  If   menu   hot-tracking   is   disabled,   your   application   needs   to   handle   these   key   press   events   in   the   following   way: 
  
  The   F10   key.   Activate   the   first   button   with   TB_SETHOTITEM.   
  The   LEFT   ARROW   and   RIGHT   ARROW   keys.   Activate   the   adjacent   button   with   TB_SETHOTITEM.   If   the   user   attempts   to   navigate   off   either   end   of   the   menu   bar,   activate   the   first   button   at   the   opposite   end.   
  The   ESCAPE   key.   Deactivate   the   active   button   with   TB_SETHOTITEM.   The   menu   bar   should   be   returned   to   the   state   it   had   prior   to   activating   the   first   button.   
  An   ALT-Key   accelerator   key.   Use   the   TB_MAPACCELERATOR   message   to   determine   which   button   the   Key   character   corresponds   to.   Display   the   button's   drop-down   menu   and   enable   menu   hot-tracking.   
  The   DOWN   ARROW   key.   If   a   button   is   active   but   no   menu   has   been   displayed,   display   the   button's   menu   and   enable   menu   hot-tracking.   
  The   ENTER   key.   Deactivate   the   active   button   with   TB_SETHOTITEM.   The   menu   bar   should   be   returned   to   the   state   it   had   prior   to   activating   the   first   button.   
  Mixed   Navigation 
  The   keyboard   navigation   handlers   outlined   in   the   preceding   section   basically   do   two   tasks:   keep   track   of   the   active   button   and   display   the   appropriate   menu   when   a   button   is   selected.   These   handlers   are   sufficient   as   long   as   the   user   navigates   only   with   the   keyboard.   However,   users   often   mix   keyboard   and   mouse   navigation.   For   example,   they   might   activate   the   first   button   with   the   F10   key,   use   the   mouse   to   activate   a   different   button,   and   then   open   its   menu   with   the   DOWN   ARROW   key.   If   you   are   only   monitoring   key   presses   to   keep   track   of   the   active   key,   you   will   display   the   wrong   menu.   You   must   also   handle   the   TBN_HOTITEMCHANGE   notification   to   accurately   keep   track   of   the   active   button. 
  
  Handling   Navigation   with   Menu   Hot-Tracking   Enabled 
  Once   menu   hot-tracking   is   enabled,   your   application   must   change   the   way   it   responds   to   user   navigation.   To   replicate   the   behavior   of   standard   menus,   you   must   implement   the   following   features   explicitly. 
  
  With   mouse   navigation: 
  
  If   the   user   moves   the   cursor   over   another   button,   that   menu   immediately   appears   and   the   previous   menu   disappears.   
  Menu   hot-tracking   stays   active   until   the   user   selects   a   command   or   clicks   a   point   that   is   not   part   of   the   menu   region.   Either   action   deactivates   menu   hot-tracking   until   another   button   is   clicked.   
  If   the   cursor   moves   off   the   menu,   the   current   drop-down   menu   remains   until   the   cursor   moves   back   onto,   or   the   user   clicks   a   point   outside,   the   area   covered   by   the   menu.   If   the   cursor   returns   to   a   different   button   than   the   one   currently   being   displayed,   the   old   menu   is   collapsed   and   the   new   menu   is   displayed.   
  With   keyboard   navigation: 
  
  The   RIGHT   ARROW   key.   If   the   item   has   a   submenu,   display   the   submenu.   If   the   item   does   not   have   a   submenu,   collapse   the   menu   and   any   submenus,   activate   the   next   button   with   TB_SETHOTITEM,   and   display   the   menu   for   the   adjacent   button.   If   the   last   button   is   active   when   this   message   is   received,   display   the   menu   for   the   first   button.   
  The   LEFT   ARROW   key.   If   the   item   is   a   submenu,   collapse   it   and   shift   focus   to   its   parent   menu.   If   the   item   is   not   a   submenu,   collapse   the   menu,   activate   the   next   button   with   TB_SETHOTITEM,   and   display   the   menu   for   that   button.   
  Pressing   the   LEFT   ARROW   key   moves   the   focus   to   the   left.   
  If   the   highlighted   menu   item   is   on   the   primary   menu,   that   menu   is   collapsed,   and   the   menu   for   the   adjacent   button   is   displayed.   If   the   active   button   was   at   the   left   end   of   the   toolbar,   the   menu   for   the   last   button   is   displayed.   
  If   the   highlighted   menu   item   is   on   a   submenu,   the   submenu   is   collapsed,   shifting   the   focus   back   to   its   parent.   
  Pressing   the   RIGHT   ARROW   key   moves   the   focus   to   the   right.   
  If   the   highlighted   menu   item   does   not   have   a   submenu,   the   menu   for   the   adjacent   button   is   displayed.   If   the   active   button   was   at   the   right   end   of   the   toolbar,   the   menu   for   the   last   button   is   displayed.   
  If   the   highlighted   menu   item   has   a   submenu,   the   submenu   is   displayed.   
  The   ESCAPE   key   backs   the   display   up   one   step.   
  If   a   submenu   is   displayed,   it   is   collapsed   and   focus   shifts   to   the   parent   menu.   
  If   a   button's   menu   is   displayed,   it   is   collapsed   and   menu   hot-tracking   is   disabled.   The   item's   button   remains   active.   
  If   no   menus   are   displayed   but   a   button   is   active,   the   button   is   deactivated   and   menu   hot-tracking   is   disabled.   
  The   UP   ARROW   and   DOWN   ARROW   keys   are   used   only   to   navigate   within   a   particular   menu.   
  The   ENTER   key   launches   the   command   associated   with   a   menu   item.   If   the   menu   item   has   a   submenu,   the   ENTER   key   displays   it.   
  As   with   the   menu   hot-tracking   disabled   case,   your   application   needs   to   handle   mouse,   keyboard,   and   mixed   navigation.   However,   the   fact   that   a   menu   is   displayed   means   that   messaging   will   have   to   be   handled   somewhat   differently. 
  
  Message   Processing   for   Menu   Hot-Tracking 
  Menu   hot-tracking   requires   that   a   menu   be   displayed   at   all   times,   apart   from   the   brief   interval   required   to   switch   to   a   new   menu.   However,   the   drop-down   menu   that   is   displayed   by   TrackPopupMenu   is   modal.   Your   application   will   continue   to   receive   some   messages   directly,   including   WM_COMMAND,   TBN_HOTITEMCHANGE,   and   normal   menu-related   messages   such   as   WM_MENUSELECT.   However,   it   will   not   receive   low-level   keyboard   or   mouse   messages   directly.   To   handle   messages   such   as   WM_MOUSEMOVE,   you   must   set   a   message   hook   to   intercept   messages   directed   to   the   menu. 
  
  When   a   drop-down   menu   is   displayed,   set   the   message   hook   by   calling   SetWindowsHookEx   with   the   idHook   parameter   set   to   WH_MSGFILTER.   All   messages   intended   for   the   menu   will   be   passed   to   your   hook   procedure.   For   example,   the   following   code   fragment   sets   a   message   hook   that   will   trap   messages   going   to   a   drop-down   menu.   MsgHook   is   the   name   of   the   hook   procedure,   and   hhookMsg   is   the   handle   to   the   procedure. 
  
  hhookMsg   =   SetWindowsHookEx(WH_MSGFILTER,   MsgHook,   HINST_THISDLL,   0); 
  
  Menu   messages   are   identified   by   setting   the   hook   procedure's   nCode   parameter   to   MSGF_MENU.   The   lParam   parameter   will   point   to   a   MSG   structure   with   the   message.   The   details   of   which   messages   need   to   be   handled,   and   how,   are   discussed   in   the   remainder   of   this   document. 
  
  Your   application   must   pass   all   messages   on   to   the   next   message   hook   by   calling   CallNextHookEx.   You   must   also   send   mouse   messages   directly   to   the   toolbar   control,   making   sure   to   convert   any   point   coordinates   to   the   toolbar   client   coordinate   space.   Sending   the   messages   directly   ensures   that   the   toolbar   control   receives   the   appropriate   mouse   messages.   For   instance,   the   toolbar   needs   to   receive   WM_MOUSEMOVE   messages   in   order   to   hot-track   its   buttons. 
  
  When   a   new   button   is   activated,   your   application   must   collapse   the   old   drop-down   menu   with   a   WM_CANCELMODE   message,   and   display   a   new   menu.   It   must   also   collapse   the   drop-down   menu   when   focus   is   taken   from   the   menu   bar   with   keyboard   navigation   or   by   clicking   outside   the   menu   area.   Whenever   you   collapse   a   menu,   you   should   free   its   message   hook   with   UnhookWindowsHookEx.   If   you   need   to   display   another   drop-down   menu,   create   a   new   message   hook.   When   a   command   is   launched,   the   menu   will   be   collapsed   automatically   but   you   must   explicitly   free   the   message   hook. 
  
  The   following   code   fragment   frees   the   message   hook   that   was   set   in   the   previous   example. 
  
  UnhookWindowsHookEx(hhookMsg); 
  
  Mouse   Navigation 
  When   a   normal   toolbar   control   hot-tracks   buttons,   it   highlights   the   active   button   and   sends   the   application   a   TBN_HOTITEMCHANGE   notification   each   time   a   new   button   is   activated.   Your   application   is   responsible   for   displaying   the   appropriate   drop-down   menu.   It   must: 
  
  Handle   the   TBN_HOTITEMCHANGE   notification   to   keep   track   of   the   active   button.   When   the   active   button   changes,   collapse   the   old   menu   and   create   a   new   one.   
  Handle   the   TBN_DROPDOWN   notification   that   is   sent   when   a   button   is   clicked.   It   should   then   collapse   the   menu   and   disable   menu   hot-tracking.   The   button   remains   active.   
  Handle   the   WM_LBUTTONDOWN,   WM_RBUTTONDOWN,   and   WM_MOUSEMOVE   messages   in   your   message   hook   procedure,   to   keep   track   of   the   mouse   position.   If   the   mouse   is   clicked   outside   the   menu   area,   collapse   the   current   drop-down   menu,   deactivate   menu   hot-tracking,   and   return   the   menu   bar   to   its   preactivation   state.   
  When   a   menu   command   is   launched,   disable   menu   hot-tracking.   The   menu   will   be   collapsed   automatically   but   you   must   explicitly   free   the   message   hook.   
  You   must   also   handle   menu-related   messaging,   such   as   the   WM_INITMENUPOPUP   message   that   is   sent   when   a   menu   item   needs   to   display   a   submenu.   For   a   discussion   of   how   to   handle   such   messages,   see   Menus. 
  
  Keyboard   Navigation 
  Your   application   must   process   keyboard   messages   in   the   message   hook   procedure   and   act   on   those   that   affect   menu   hot-tracking.   The   following   key   presses   need   to   be   handled: 
  
  The   ESCAPE   key.   The   ESCAPE   key   backs   the   display   up   one   level.   If   a   submenu   is   being   displayed,   it   must   be   collapsed.   If   a   button's   primary   menu   is   displayed,   collapse   it   and   disable   menu   hot-tracking.   The   button   remains   active.   
  The   RIGHT   ARROW   key.   If   the   item   has   a   submenu,   display   it.   If   the   item   does   not   have   a   submenu,   collapse   the   menu   and   any   submenus,   activate   the   next   button   with   TB_SETHOTITEM,   and   display   its   menu.   If   the   last   button   was   active   when   this   notification   was   received,   display   the   menu   for   the   first   button.   
  The   LEFT   ARROW   key.   If   the   item   is   in   a   submenu,   collapse   it   and   shift   focus   to   its   parent   menu.   If   the   item   is   not   a   submenu,   collapse   the   menu,   activate   the   adjacent   button   with   TB_SETHOTITEM,   and   display   its   menu.   If   the   first   button   was   active   when   this   notification   was   received,   display   the   menu   for   the   last   button.   
  The   UP   ARROW   and   DOWN   ARROW   keys.   These   keys   are   used   to   navigate   within   a   menu   but   do   not   directly   affect   menu   hot-tracking.   
  An   ALT-Key   accelerator   key.   Use   the   TB_MAPACCELERATOR   message   to   determine   which   button   the   Key   character   corresponds   to.   If   it   corresponds   to   a   different   button   than   the   currently   active   one,   collapse   the   current   drop-down   menu,   activate   the   new   button   with   TB_SETHOTITEM,   and   display   the   menu   for   the   adjacent   button.   If   the   Key   character   corresponds   to   the   currently   displayed   button,   collapse   the   drop-down   menu   and   disable   menu   hot-tracking.   The   button   should   remain   active.   
  ©   2000   Microsoft   Corporation.   All   rights   reserved.   Terms   of   use. 
 
Top
69楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-05-02 11:15:00  得分 0

111222快来看啊,jifeng给处解答了,为什么我给不了分? 
  http://msdn.microsoft.com/library/psdk/shellcc/CommCtls/FAQ/iemenubar.htm
Top
70楼  ookaiii   (IUnknown* pIWorld) 三级用户 该版得分小于等于1000分,大于500分  回复于 2001-05-02 11:16:00  得分 0

好了,分给过了!
Top
相关问题

    * 各位:我现在想在CReBar上设置CMenu,调用CReBar::SetMenu(...)为什么会不行?正确的做法应该是怎样的?
    * 各位:我现在想在CReBar上设置CMenu,调用CReBar::SetMenu(...)为什么会不行?正确的做法应该是怎样的?ToolBar上怎样添加菜单?

网站简介-广告服务-网站地图-帮助信息-联系方式-English-问题报告

CSDN北京百联美达美数码科技有限公司  版权所有  京 ICP 证 020026 号 CSDN

© 2000-04, CSDN.NET, All Rights Reserved
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值