Hi,

I have a dialog that contains a group of 3 radio buttons. When the user taps
on a radio button, under certain conditions, I want to disallow the change of
this setting. In my handler, I am doing this:

case BUTTON1:
if (change_allowed())
do_additional_processing();
else {
CheckRadioButton(hwnd, BUTTON1, BUTTON3, BUTTON1 + original_value);
MessageBox(show error that this change is not allowed);
}
break;

Running this code, if I tap on BUTTON1, and change_allowed returns false, I
get into an infinite loop. The error message is displayed, I tap on OK, but
the BUTTON1 handler gets called again, the error message is displayed again,
etc.

If I do the call to MessageBox before the call to CheckRadioButton, things
seem to work correctly. The error message is displayed, I tap on OK, and it
goes away. But if I then do something else that displays another dialog
(e.g., my application's About dialog), when I return to the original screen,
my error message is displayed again! For some reason, the system is sending a
WM_COMMAND for BUTTON1 upon return from the other dialog.

It doesn't seem to make any difference if I return 0 or 1 from the BUTTON1
handler. It also doesn't seem to help if I check or uncheck the Auto property
for the buttons. I'm using EVC4 in case it matters.

Can someone please tell me what I'm doing wrong? How can I show an error
message and then set the radio button selection back to the original value?
(I don't want to just disable the button, because I want the user to be able
to tap on it and get a meaningful error message.)

Thanks!
E.D.

Re: Problem with CheckRadioButton by r_z_aret

r_z_aret
Mon Nov 15 17:32:45 CST 2004

On Thu, 11 Nov 2004 12:44:14 -0800, "E.D."
<ED@discussions.microsoft.com> wrote:

>Hi,
>
>I have a dialog that contains a group of 3 radio buttons. When the user taps
>on a radio button, under certain conditions, I want to disallow the change of
>this setting. In my handler, I am doing this:
>
>case BUTTON1:
> if (change_allowed())
> do_additional_processing();
> else {
> CheckRadioButton(hwnd, BUTTON1, BUTTON3, BUTTON1 + original_value);

I suspect this call is the problem; perhaps it triggers a BN_CLICKED,
which you handle by calling the function, etc. Have you tried
returning 1 _without_ calling CheckRadioButton and/or making sure the
default window proc isn't called?


> MessageBox(show error that this change is not allowed);
> }
> break;
>
>Running this code, if I tap on BUTTON1, and change_allowed returns false, I
>get into an infinite loop. The error message is displayed, I tap on OK, but
>the BUTTON1 handler gets called again, the error message is displayed again,
>etc.
>
>If I do the call to MessageBox before the call to CheckRadioButton, things
>seem to work correctly. The error message is displayed, I tap on OK, and it
>goes away. But if I then do something else that displays another dialog
>(e.g., my application's About dialog), when I return to the original screen,
>my error message is displayed again! For some reason, the system is sending a
>WM_COMMAND for BUTTON1 upon return from the other dialog.
>
>It doesn't seem to make any difference if I return 0 or 1 from the BUTTON1
>handler. It also doesn't seem to help if I check or uncheck the Auto property
>for the buttons. I'm using EVC4 in case it matters.
>
>Can someone please tell me what I'm doing wrong? How can I show an error
>message and then set the radio button selection back to the original value?
>(I don't want to just disable the button, because I want the user to be able
>to tap on it and get a meaningful error message.)

If neither suggestion I make above works, then my only other idea is
rather kludgy. Something like:
1) post a private message instead of calling CheckRadioButton
2) handle that message by setting a BOOL to TRUE and then calling
CheckRadioButton
3) in the BN_CLICKED handler,
a) allow change if either change_allowed() returns TRUE _or_ the BOOL
is TRUE
b) set the BOOL to FALSE


>
>Thanks!
>E.D.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com