-
radio buttons
I'm just beginning programming in windows, and I added radio buttons to my dialog box and I can't get them to work. Which function should I use to say "If this radio button is activated, do this."? I looked in MSDN, and I tried using BN_CLICKED but I can't get it to work, and when I tried to use switch(wCommand){
case IDC_RADIO1: function();
break;
}
The program does function() the moment the user clicks on the radio button, instead of waiting until the user presses ok.
I'd appreciate any help if you have suggestions,
Thanks in advance,
Ron
P.S. Thank you Sunlight for your wonderful tutorial, it really helped me alot getting started!
-
check out these API's
CheckDlgButton() and IsDlgButtonChecked().
this checks the radio button, if it's already checked it uncecks it.
Code:
case IDC_RADIO1:
if(IsDlgButtonChecked(hwnd, IDC_RADIO1) == BST_CHECKED)
{
CheckDlgButton(hwnd, IDC_RADIO1, BST_UNCHECKED);
}
else
{
CheckDlgButton(hwnd, IDC_RADIO1, BST_CHECKED);
}
break;
hope it helps
-
i think i may have misunderstood your question. let me see if this better.
Code:
case IDOK: // ID of your OK button
if(IsDlgButtonChecked(hwnd, IDC_RADIO1) == BST_CHECKED)
{
// if the radio button is checked do your stuff
}
else
{
// if its not do your other stuff
}
break;
-
To get it to wait until the user presses the OK button, put your IsDlgButtonChecked() within the case for the OK button. For example:
case WM_COMMAND:
if(wParam==IDOK)
{
if (IsDlgButtonChecked(hwndDlg,SAVE))
EndDialog(hwndDlg,SAVE);
return TRUE;
}
In this example, if the SAVE dialog button is checked, the dialog box is hidden, and the program returns to the where the dialog box was created. If you want to keep the dialog box active, do your processing, and take out the EndDialog() statement.
-
Forgot to format the code:
Code:
case WM_COMMAND:
if(wParam==IDOK)
{
if (IsDlgButtonChecked(hwndDlg,SAVE))
EndDialog(hwndDlg,SAVE);
return TRUE;
}
-