-
March 26th, 2010, 02:40 AM
#1
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!
-
March 26th, 2010, 03:20 AM
#2
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)
Victor Nijegorodov
-
March 26th, 2010, 03:55 AM
#3
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.
-
March 28th, 2010, 10:54 AM
#4
Re: Problems with radio button
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|