c++mfctoolbarcmfctoolbar

MFC: CMFCToolBar SetButtonStyle not wirking with style TBBS_PRESSED?


byIs there are bug in control ? or I am doing something wrong ?

In .h
CMFCToolBar m_wndToolBar;
in message map
ON_COMMAND(ID_MYID, &CMainFrame::OnToolBar)

void CMainFrame::OnToolBar()
{
int nIndex = m_wndToolBar.CommandToIndex(ID_MYID);
UINT nState = m_wndToolBar.GetButtonStyle(nIndex);
if(nState & TBBS_PRESSED)
nState &= ~TBBS_PRESSED;
else
nState |= TBBS_PRESSED;
m_wndToolBar.SetButtonStyle(nIndex,nState);
m_wndToolBar.InvalidateButton(nIndex);
}

By clicking on button I need to set button pressed, and when user clicked again, button become unpressed.

Nothing happens by clicking on button :(


Solution

  • Just create an ON_UPDATE_COMMAND handler for the specific item. Use pCmdUI->SetCheck to Signal the down or Up state.

    The MFC updates tool bars and menus never directly. They ask the Framework to update the state of the Buttons and menu items.