1
votes

I have this COM control with a group of radio buttons, which is associated with an integer variable to identify the checked radio button.

This associated variable is saved/loaded through DoPropExchange(), therefore, backward compatibility is a must, i.e. the checked radio button saved by old version should be able to be carried over to the newer version, even though in the newer version, the tab order of the radio buttons have been changed.

But after I added additional radio buttons into the group and changed the tab orders, when I was trying to load an old version of this control, there is no radio button checked! I ran it in debug mode and found that the associated integer was correctly loaded.

Thanks in advance! James

1
Check the "radio button issues" section in flounder.com/guiowner.htm. I don't know if it can help you right now with your backward compatibility problem, but it gives really valuable tips on how to work with radio buttons in a maintainable way.MikMik
That's a nice article, well explained and very helpful! Many thanks, Jamesjames

1 Answers

3
votes

The buttons work nice with proper group and tab order, as you mentioned. However at any time each button is still a window, with BM_SETCHECK applicable, CButton::SetCheck is the MFC wrapper.

You can update buttons check state invidually, esp. handling BN_CLICKED notification from all radio buttons and updateing check state on all other radio buttons respectively.

Something you might possibly need to correctly check a button:

INT m_nIndex;
// ...
// (there a power from above loads nIndex from persistent storage)
// ...
CButton* pButton1 = (CButton*) GetDlgItem(IDC_RADIO1);
CButton* pButton2 = (CButton*) GetDlgItem(IDC_RADIO2);
CButton* pButton3 = (CButton*) GetDlgItem(IDC_RADIO3);
pButton1->SetCheck(m_nIndex == 0);
pButton1->SetCheck(m_nIndex == 1);
pButton1->SetCheck(m_nIndex == 2);