DeathToBoxes
June 1st, 2009, 04:11 PM
I have four radio buttons used to set the game difficulty. They are easy, medium, hard, and custom. If the user clicks on the custom radio button it brings up a dialog box that allows them to enter a custom difficulty value between 2 and 80. If they click the cancel button within the dialog box I do not want the custom radio button to be checked. My problem is that if the user clicks cancel in the dialog box the dialog box is reloaded when the user clicks anywhere on the window. Basically if the CheckRadioButton() function is not called within the MENU_CUSTOM case statement then the very next WM_COMMAND message will always be for the MENU_CUSTOM radio button.
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case MENU_EASY:
{
game.difficulty = 34;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_EASY);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_MEDIUM:
{
game.difficulty = 30;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_MEDIUM);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_HARD:
{
game.difficulty = 26;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_HARD);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_CUSTOM:
{
int oldpos = si.nPos;
si.nPos = game.difficulty;
si.nMax = 80;
si.nMin = 2;
if ( DialogBox(Main.GetInstance(), "DialogCustom", Main.GetHandle(), DialogProcedure) == BUTTON_OK )
{
char string[11] = "Custom: ";
game.difficulty = si.nPos;
string[8] = (game.difficulty / 10) + 48;
string[9] = (game.difficulty % 10) + 48;
string[10] = 0;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_CUSTOM);
SetWindowText( HWND(lParam), string);
}
si.nPos = oldpos;
si.nMax = 99;
si.nMin = 1;
break;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case MENU_EASY:
{
game.difficulty = 34;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_EASY);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_MEDIUM:
{
game.difficulty = 30;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_MEDIUM);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_HARD:
{
game.difficulty = 26;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_HARD);
SetWindowText(GetDlgItem(hDlg, MENU_CUSTOM), "Custom...");
break;
}
case MENU_CUSTOM:
{
int oldpos = si.nPos;
si.nPos = game.difficulty;
si.nMax = 80;
si.nMin = 2;
if ( DialogBox(Main.GetInstance(), "DialogCustom", Main.GetHandle(), DialogProcedure) == BUTTON_OK )
{
char string[11] = "Custom: ";
game.difficulty = si.nPos;
string[8] = (game.difficulty / 10) + 48;
string[9] = (game.difficulty % 10) + 48;
string[10] = 0;
CheckRadioButton(hDlg, MENU_EASY, MENU_CUSTOM, MENU_CUSTOM);
SetWindowText( HWND(lParam), string);
}
si.nPos = oldpos;
si.nMax = 99;
si.nMin = 1;
break;
}