Problem with hidden radio button causing crash

I have an MFC application with a dialog that uses radio buttons.  In the OnInitDialog for the dialog with the radio buttons I programmatically choose to either EnableWindow(FALSE) or ShowWindow (SW_HIDE) for two of the four radio buttons in a group if those buttons aren't appropriate for the current state.  Either of these options causes the application to crash when UpdateData(TRUE) is called in the overridden OnOK function.  The crash occurs at the ASSERT shown below in MFC dlgdata.cpp.  Is there a way to make this work?  If I leave all radio buttons enabled, it all works fine.  


// walk all children in group
int iButton = 0;
do
{
if (::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON)
{
// control in group is a radio button
if (pDX->m_bSaveAndValidate)
{
      if (::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0)
      {
      ASSERT(value == -1);    // only set once
      value = iButton;
      }
}
else
{
// select button
::SendMessage(hWndCtrl, BM_SETCHECK, (iButton == value), 0L);
}
iButton++;
}
else
{
TRACE(traceAppMsg, 0, "Warning: skipping non-radio button in group.\n");
}
hWndCtrl = ::GetWindow(hWndCtrl, GW_HWNDNEXT);

} while (hWndCtrl != NULL &&
            !(GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP));


Thanks for your help.

David
dcoggin1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
So it is not a crash but an assertation message and you will not see it in the release version.
Can you remove EnableWindow calls related to the radio buttons and groups? It does not fit to this situation.
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dcoggin1Author Commented:
Yes, I should have said I'm getting an assertion message.  I don't understand your response.  Are you saying that I will always get the assertion message if I selectively enable and disable radio buttons in a group?  If I only disable one button with EnableWindow(FALSE) or hide one button with ShowWindow(SW_HIDE), I will get the assertion message.  I have tried it with the disabled/hidden button being the last in the group and I still get an assertion message.  If I remove the calls, it works fine.  Thanks for your help.

David
0
dcoggin1Author Commented:
Well, I believe I figured out the problem.  I thought that the MFC framework called UpdateData(FALSE) upon return from my OnInitDialog, but apparently it calls it during the CDialog::OnInitDialog call at the first of my OnInitDialog.  The radio button being hidden or disabled was selected at the time it was hidden or disabled.  Even though I could still select another enabled button normally, the selected stated of the hidden/disabled button was apparently kept.  When I added an UpdateData(FALSE) call at the end of the OnInitDialog function, it all works as expected with the hidden and disabled buttons.  Thanks again for your help.

David
0
pgnatyukCommented:
I'd say, you are right. I also remember something like that.
You are welcome
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.