Problems with radio button
hi guys,
i have a set of codes under a radio button "OnBnClickedRadio()".
it will process some action on a image if it is check .
The problem im facing is when the radio button is check, i would like to process the codes only once because if i continue clicking on the radio button, it will still process those codes to the image.
is there a function to set when the radio button is being check, it will only process the codes 1 time? i cant seem to find any help here.
advance thanks to any help!
Re: Problems with radio button
Implement a boolean variable (declare it as a class member) and assign it the initial state of your radio button (as unchecked).
Then in your OnBnClickedRadio() message handler check the previous state of the button before doing your process. Something like this:
Code:
// header file
protected:
BOOL m_bChecked;
....
// .cpp file
// ctor
CMyClass::CMyClass()
{
m_bChecked = FALSE;
}
....
CMyClass::OnBnClickedRadio()
{
if( !m_bChecked )
{
// do something
}
m_bChecked = TRUE;
}
Note that you also must change m_bChecked to FALSE every time this button is unchecked (when some other radio button in the same group is checked)
Re: Problems with radio button
I would do it differently. Add a integer variable to your class that will remember the index of the selected radio button. Then in your onclick handler, you see if the previously selected radio button is different from this radio button. When it's different, do your action and update the member variable to reflect the new selected radiobutton.
Re: Problems with radio button