为什么我无法捕获ToolBar事件? [英] Why i can't catch the ToolBar events ?

查看:109
本文介绍了为什么我无法捕获ToolBar事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的对话框,其中包含4个按钮. 我想更改这4个按钮,并使ToolBar包含4个按钮,并且将完全像那些按钮一样工作.

I have simple dialog that contain 4 buttons. I want to change those 4 button and make ToolBar that contain 4 button and will act exactly like those buttons.

在h文件CMFCToolBar中;

In the h file CMFCToolBar ;

在OnInitDialog方法中,我将此代码称为:

In the OnInitDialog method i call this code:

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事件
  • 但是可喜的是,在工具栏中没有单击任何happand =>,并且单击时工具栏按钮显示为灰色.

    But what happand is that in the toolbar click nothing happand => and the toolbar button is gray out when click.

    该怎么办? 我做错了什么?

    What to do ? What i did wrong ?

    推荐答案

    您所遵循的过程在Visual Studio 2010中是正确的.

    The procedure you are following is correct with visual studio 2010.

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

    If you try again in a new MFC project, dialog-based:

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

    行得通吗?

    这篇关于为什么我无法捕获ToolBar事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆