In an application I've written, I've got a dialog box with some radio buttons, as shown below. I test for them in the usual way of a switch statement in a callback proc as shown, although I don't know how to link them so that if one is pressed, the others are deactivated and the one which is pressed is activated.
Code:
/* resource.rc */
IDD_OPTIONS DIALOG DISCARDABLE 50, 50, 120, 120
STYLE DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME
CAPTION "Options"
FONT 8, "MS Sans Serif"
BEGIN
RADIOBUTTON "640x480", IDC_NEW_RADIO1, 30, 20, 30, 15
RADIOBUTTON "800x600", IDC_NEW_RADIO2, 70, 20, 30, 15
RADIOBUTTON "1024x768", IDC_NEW_RADIO3, 30, 60, 30, 15
RADIOBUTTON "1600x1200", IDC_NEW_RADIO4, 70, 60, 30, 15
/* More options here */
END
Code:
/* This is part of my main.cpp */
BOOL CALLBACK OptionsDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
BOOL ret = FALSE;
/* Returns TRUE if everything goes smoothly, FALSE otherwise */
switch(Message)
{
case WM_INITDIALOG:
ret = TRUE;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_NEW_RADIO1:
/* Activate current option in the dialog, while deactivating the others */
ret = TRUE;
break;
case IDC_NEW_RADIO2:
ret = TRUE;
break;
case IDC_NEW_RADIO3:
ret = TRUE;
break;
case IDC_NEW_RADIO4:
ret = TRUE;
break;
}
break;
default:
// ret = FALSE;
break;
}
return ret;
}