Radio buttons are normally used to provide the user a choice from a number of mutually excussive, predefined items.In this example the user can send a message or ask for a number. Only one of the buttons can be selected at a given time, so if Send a message were selected then Ask for a Number would be automatically deselected.
To add radio buttons to a dialog box, decide ahead how many will be used and if they are show in a column (as seen here) or in a row. Select the radio button tool you want to use from the two given circular (shown here) or diamond shaped. Place the first radio box in your column or row then select duplicate from the edit menu. You are asked for the number of rows or columns. In the example there are 2 rows and one column.
You may want to leave spacing at zero, but if you choose 5 there is a bit of room to adjust by hand later. Once the radio buttons are on the screen, you want to edit each and add appropriate text for the screen and a control number that is useful. Select the first button in the row or column and alter it. When you have finished the first, the second will appear.
After you have edited it, the next will appear. This continues until all buttons have text and control numbers. The class that executes this dialog can have a transfer buffer declared. The transfer buffer for buttons is a set of bool values (one for each button).
When you are done creating the dialog box in the resource workshop, return to your program and create the class representing this dialog using the class expert.
To create a transfer buffer for the buttons select each of the ids for your buttons from the Control Notification Pane. Use the right button to create an instance variable for each.
Once you have created these instances, you will automatically get the following transfer button definition in your class header.
//{{TDialog = SendMessageDlg}}
struct SendMessageDlgXfer {
//{{SendMessageDlgXFER_DATA}}
bool _ask;
bool _send;
//{{SendMessageDlgXFER_DATA_END}}};
Once again add a constructor with the transfer buffer as first parameter.
SendMessageDlg::SendMessageDlg (SendMessageDlgXfer *tb,TWindow* parent, TResId resId, TModule* module)
: TDialog(parent, resId, module)
{
//{{SendMessageDlgXFER_USE}}
_ask = new TRadioButton(this, IDC_ASK, 0);
_send = new TRadioButton(this, IDC_SEND, 0);
SetTransferBuffer(tb);
//{{SendMessageDlgXFER_USE_END}}
// Change the window's background color
SetBkgndColor(GetSysColor(COLOR_APPWORKSPACE));
// INSERT>> Your constructor code here.
}
Finally, when you use the dialog, set one of the values true and the others false. After execution, one of the bool values will be true (the one selected by the user) and the others false.
void MesspassMDIChild::cmGetDialog ()
{
// INSERT>> Your code here.
SendMessageDlgXfer tb; tb.
_ask = true; tb.
_send = false;
if (SendMessageDlg(&tb,this).Execute()==IDOK)
{
if(tb._ask)
Parent->PostMessage(WM_ASK);
else
Parent->PostMessage(WM_SEND); }
}