Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling buttons in dialog box

Status
Not open for further replies.

DoctorC

Programmer
Jun 29, 2000
34
US
If I have several radio buttons, can I enable or disable a command button depending on which radio button is clicked?&nbsp;&nbsp;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?&nbsp;&nbsp;I thought of using an <font color=red>ON_UPDATE_COMMAND_UI</font> macro, with the handler function containing an &quot;<font color=red>if</font>&quot; statement checking the variables mapped to the radio controls, but I think <font color=red>DoDataExchange</font> doesn't get called yet to set the values.&nbsp;&nbsp;Any other ideas how I can dynamically handle the state of a button (or edit box, etc) according to selections made by the user?
 
I would make a private boolean variable that I could toggle depending on which button the user pressed.&nbsp;&nbsp;And then enable or disenable the buttons depending on the state of the boolean.
 
Thanks for your quick reply.&nbsp;&nbsp;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.&nbsp;&nbsp;I am hoping to enable/disable a button before &quot;OK&quot; or &quot;Cancel&quot; are clicked.&nbsp;&nbsp;The answer might be right in front of my eyes, but I am just not seeing it.
 
Dear DoctorC,<br><br>If I understand your stated problem correctly, try this:<br><br>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). <br><br>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'.<br><br>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'.<br><br>Now create a member function for your dialog say you call it 'onRadio' so the function body looks like this:<br><br>void MyDialog::eek:nRadio(){<br>}<br><br>Now in each of the 'BN_CLICK' handlers for the radio controls add a call to 'onRadio()'.<br><br>Now add this code to the 'onRadio' function of course changing it in such a way that it generates your desired behavior.<br><br>UpdateData();<br>switch( _nRadio){<br>case 0:<br> _btnOne.EnableWindow( FALSE);<br> _btnTwo.EnableWindow( TRUE);<br> break;<br>case 1:<br> _btnOne.EnableWindow( TRUE);<br> _btnTwo.EnableWindow( FALSE);<br> break;<br>case 2:<br> _btnOne.EnableWindow( TRUE);<br> _btnTwo.EnableWindow( TRUE);<br> break;<br>}<br><br><br>Hope this helps<br>-pete<br>
 
Thanks Pete<br><br>I haven't tried it yet, but your suggestion sounds right on.&nbsp;&nbsp;If you don't see another response here from me, you can assume it worked.&nbsp;&nbsp;Thanks again<br><br>Dr.C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top