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 :(

有帮助吗?

解决方案

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.

其他提示

Your description indicates that you want the button to have the behavior of a "check box". If that is correct, make sure you specify TBBS_CHECKBOX for the button style. You should not need to manually handle rendering the check box state each time the button is pressed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top