I am using win 32 api in C to devellop a desktop app. At on point I want to use a radio button with two case, and depending on what case is selected by the user I want to create a dialogBox.
I use a ressource file to create the dialog box that contains the radio button :
IDD_INPUT DIALOG DISCARDABLE 0, 0, 150, 150
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION
CAPTION "Pricing Input"
FONT 8, "MS Sans Serif"
BEGIN
RADIOBUTTON "Historical Data",IDC_HISTO,20, 20, 50,14
RADIOBUTTON "User Inpu",IDC_USER,90,20,50,14
PUSHBUTTON "Ok",IDC_VALID,60,100,50,14
END
The dialog box is created as follow :
hWndDlgBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INPUT), hWnd, (DLGPROC)DlgInput);
And the DlgInput procedure is something like:
LRESULT CALLBACK DlgInput(HWND hWnDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_INITDIALOG:
{
return TRUE;
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_VALID:
{
if (GetDlgItem(hWnDlg, IDC_USER)) {
// Open dialog box x
}
else {
//Open dialog box y
}
SendMessage(hWnDlg, WM_CLOSE, 0, 0);
}
break;
}
case WM_CLOSE:
DestroyWindow(hWnDlg);
hWndDlgBox = NULL;
break;
default:
return FALSE;
break;
}
}
}
So in the IDC_VALID case I want to check the value of the radio button, I tried using the GetDlgItem function but I don't really understand what value it returns. I saw that it's possible to use the BM_GETCHECK message but I'm not sure how to use it. Also when I click on one case the dialog box closes and I don't know why.
Can someone explain to me how the radio button work ?
CodePudding user response:
You could try to send the BM_GETCHECK message to the control and check the return value. And you will need the HWND of your control, to get that from the control ID, you could try to call GetDlgItem().
