【问题标题】:Why i can't catch the ToolBar events ?为什么我无法捕捉工具栏事件?
【发布时间】:2012-09-19 06:29:02
【问题描述】:

我有一个包含 4 个按钮的简单对话框。 我想更改这 4 个按钮并制作包含 4 个按钮的 ToolBar,并且其行为与这些按钮完全相同。

在h文件CMFCToolBar中;

在 OnInitDialog 方法中,我调用此代码:

if(m_ToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, 100 ) )
{
    m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() & ~( CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_ANY ) );

    m_ToolBar.InsertButton( CMFCToolBarButton( IDC_BTN_1, -1 , _T("Txt_1") ) );
    m_ToolBar.InsertButton( CMFCToolBarButton( IDC_BTN_2, -1 , _T("Txt_2") ) );
    m_ToolBar.InsertButton( CMFCToolBarButton( IDC_BTN_3, -1 , _T("Txt_3") ) );
    m_ToolBar.InsertButton( CMFCToolBarButton( IDC_BTN_4, -1 , _T("Txt_4") ) );

    CSize size = m_ToolBar.CalcFixedLayout( FALSE, TRUE );
    m_ToolBar.SetWindowPos( NULL, 0, 0, size.cx + 10, size.cy + 10 , SWP_NOACTIVATE | SWP_NOZORDER );

}
  • IDC_BTN_XX 与原始按钮的 ID 相同 => 所以在 BEGIN_MESSAGE_MAP 中我没有更改任何内容 => 所以我想获得与之前相同的 Click 事件

但是,在工具栏中单击没有发生任何事情 => 并且工具栏按钮在单击时显示为灰色。

怎么办? 我做错了什么?

【问题讨论】:

    标签: visual-c++ user-interface mfc


    【解决方案1】:

    您所遵循的过程对于 Visual Studio 2010 是正确的。

    如果您在新的 MFC 项目中重试,基于对话框:

    • 添加按钮 IDC_BUTTON1
    • 管理点击代码
    • 使用您在此处建议的相同代码添加工具栏

    有效吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 2017-01-22
      • 2017-09-26
      • 2014-12-22
      • 1970-01-01
      • 2019-12-29
      • 2010-11-01
      相关资源
      最近更新 更多