No war whatsoever guys.
Here is some code where I ineract with some buttons on my game's config program to choose resolution. It uses the win32 api to interact with the various controls on the dialog. It's fairly straightforward and clean:
//get the resolution selection
LRESULT ResSel = SendMessage(hListRes,LB_GETCURSEL,0,0);
if (ResSel == LB_ERR) nRes = 0;
else nRes = ResSel;
if (IsDlgButtonChecked(hMain,IDC_CHK_FULLSCREEN) == BST_CHECKED)
bFullScreen = true;
else bFullScreen = false;
if (IsDlgButtonChecked(hMain,IDC_CHK_VSYNC) == BST_CHECKED)
bVSync = true;
else bVSync = false;
if (IsDlgButtonChecked(hMain,IDC_CHK_SOUND) == BST_CHECKED)
bSound = true;
else bSound = false;
Here is quick code where I toggle back the default values, once again very clean.
void DefaultConfig(void)
{
CheckDlgButton(hMain,IDC_CHK_FULLSCREEN,BST_CHECKED);
CheckDlgButton(hMain,IDC_CHK_VSYNC,BST_CHECKED);
CheckDlgButton(hMain,IDC_CHK_SOUND,BST_CHECKED);
SendMessage(hListRes,LB_SETCURSEL,0,0);
return;
}
The base of the program couldn't be simpler...
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nStyle)
{
//load the config dialog
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLG1), NULL, (DLGPROC)DlgProc);
return 0;
}
LRESULT CALLBACK DlgProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HRESULT hRes;
switch(Msg)
{
case WM_INITDIALOG:
{
//grab all the controls, and toggle
//their default states
hMain = hWnd;
hListRes = GetDlgItem(hMain,IDC_RESLIST);
hChkFullScreen = GetDlgItem(hMain,IDC_CHK_FULLSCREEN);
hChkVSync = GetDlgItem(hMain,IDC_CHK_VSYNC);
hChkSound = GetDlgItem(hMain,IDC_CHK_SOUND);
BuildList();
//if the config file cannot be loaded,
//set the default options
DefaultConfig();
LoadConfig();
}break;
case WM_COMMAND:
{
switch( LOWORD(wParam) )
{
case IDC_BTN_SAVE:
{
SaveConfig();
EndDialog(hMain,0);
break;
}
case IDC_BTN_CANCEL:
{
EndDialog(hMain,0);
break;
}
case IDC_BTN_DEFAULT:
{
DefaultConfig();
break;
}
}break;
}
//window being destroyed
case WM_CLOSE:
case WM_QUIT:
case WM_DESTROY:
{
EndDialog(hMain,0);
break;
}
default:
return false; // Didn't handle message
}
return true;
}
I've written lots of little things over the past year since I got more comfortable with win32 api, and it's all simple and clean. I have something that is way more complicated archived around here somewhere with tabbed pages inside a dialog and all this other junk and it's still clean and straightforward. :|