Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Enabling buttons in dialog box

Enabling buttons in dialog box

Enabling buttons in dialog box

If I have several radio buttons, can I enable or disable a command button depending on which radio button is clicked?  For example, if 3 radio buttons in a group are labeled WHITE, BLACK, and GRAY, can I enable a command button on the same dialog only if WHITE or BLACK are checked, but not GRAY?  I thought of using an ON_UPDATE_COMMAND_UI macro, with the handler function containing an "if" statement checking the variables mapped to the radio controls, but I think DoDataExchange doesn't get called yet to set the values.  Any other ideas how I can dynamically handle the state of a button (or edit box, etc) according to selections made by the user?

RE: Enabling buttons in dialog box

I would make a private boolean variable that I could toggle depending on which button the user pressed.  And then enable or disenable the buttons depending on the state of the boolean.

RE: Enabling buttons in dialog box

Thanks for your quick reply.  I'm afraid I'm still not getting it...how does that private boolean variable get set in a modal dialog if nothing else has been clicked.  I am hoping to enable/disable a button before "OK" or "Cancel" are clicked.  The answer might be right in front of my eyes, but I am just not seeing it.

RE: Enabling buttons in dialog box

Dear DoctorC,

If I understand your stated problem correctly, try this:

Open Class Wizard and select the 'Member Variables' tab. You should see a single entry for all the radio buttons with the Control ID of the first in the group. Create a member variable for that control, say you name it ( _nRadio).

Now create a 'Control' type variable for each of the 'Buttons' you want to enable/disable say there are two and you name the variables '_btnOne' and '_btnTwo'.

Now click the 'Message Map' tab on the Wizard dialog. Create a handler for each radio button Control's BN_CLICKED messsage. Now click 'OK'.

Now create a member function for your dialog say you call it 'onRadio' so the function body looks like this:

void MyDialog::onRadio(){

Now in each of the 'BN_CLICK' handlers for the radio controls add a call to 'onRadio()'.

Now add this code to the 'onRadio' function of course changing it in such a way that it generates your desired behavior.

switch( _nRadio){
case 0:
_btnOne.EnableWindow( FALSE);
_btnTwo.EnableWindow( TRUE);
case 1:
_btnOne.EnableWindow( TRUE);
_btnTwo.EnableWindow( FALSE);
case 2:
_btnOne.EnableWindow( TRUE);
_btnTwo.EnableWindow( TRUE);

Hope this helps

RE: Enabling buttons in dialog box

Thanks Pete

I haven't tried it yet, but your suggestion sounds right on.  If you don't see another response here from me, you can assume it worked.  Thanks again


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close