Tech Support > Microsoft Windows > Development Resources > Checking radio buttons
Checking radio buttons
Posted by William Payne on April 13th, 2004


Hello, in my program written in C++ using pure Win32 I have a dialog box
with two groups of radio buttons. Under WM_INITDIALOG I check a button in
each group like this:

SendMessage(resolution_1280_1024_radio_button, BM_SETCHECK, BST_CHECKED, 0);
SendMessage(color_depth_32_radio_button, BM_SETCHECK, BST_CHECKED, 0);

After these two calls the buttons are checked as they should. But, if I ask
my program to tell me which radio buttons are checked it says no buttons are
checked unless I change the initial checks. Why? Isn't BM_SETCHECK enough?
The two function for determining the state of each group of radio buttons
looks like this:

void get_resolution(HWND resolution_1280_1024_radio_button,
HWND resolution_1024_768_radio_button,
HWND resolution_800_600_radio_button,
int* width,
int* height)
{
if(SendMessage(resolution_1280_1024_radio_button, BM_GETCHECK, 0, 0) ==
BST_CHECKED)
{
(*width) = 1280;
(*height) = 1024;
}
else if(SendMessage(resolution_1024_768_radio_button, BM_GETCHECK, 0, 0)
== BST_CHECKED)
{
(*width) = 1024;
(*height) = 768;
}
else if(SendMessage(resolution_800_600_radio_button, BM_GETCHECK, 0, 0)
== BST_CHECKED)
{
(*width) = 800;
(*height) = 600;
}

(*width) = -1;
(*height) = -1;

throw "Error in get_resolution()";
}

void get_color_depth(HWND color_depth_32_radio_button,
HWND color_depth_16_radio_button,
HWND color_depth_8_radio_button,
int* color_depth)
{
if(SendMessage(color_depth_32_radio_button, BM_GETCHECK, 0, 0) ==
BST_CHECKED)
{
(*color_depth) = 32;
}
else if(SendMessage(color_depth_16_radio_button, BM_GETCHECK, 0, 0) ==
BST_CHECKED)
{
(*color_depth) = 16;
}
else if(SendMessage(color_depth_8_radio_button, BM_GETCHECK, 0, 0) ==
BST_CHECKED)
{
(*color_depth) = 8;
}

(*color_depth) = -1;

throw "Error in get_color_depth()";
}

What am I doing wrong?

/ WP


Posted by William Payne on April 13th, 2004



"William Payne" <mikas_n_o_s_p_a_m_493@student.liu.se> wrote in message
news:c5hn7h$s8e$1@news.island.liu.se...
Found the silly bug...I needed to exit the
get_resolution()/get_color_depth() functions if I found a check or else
execution would continue all the way to throwing of exceptions.

/ WP




Similar Posts