Why i can't catch the ToolBar events ?

2019-06-07 05:20发布

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.

In the h file CMFCToolBar ;

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 );

}
  • The IDC_BTN_XX is same ID as the original button => so in the BEGIN_MESSAGE_MAP i did not change anything => so i want to get the same Click event as before

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 ?

1条回答
戒情不戒烟
2楼-- · 2019-06-07 06:01

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

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

  • Add a button IDC_BUTTON1
  • Manage the click code
  • Add toolbar with the same code you have proposed here

Does it work?

查看更多
登录 后发表回答