문제

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