[英]How to check what case is selected with radio button Win 32 api
I am using win 32 api in C++ to devellop a desktop app.我在 C++ 中使用 win 32 api 来开发桌面应用程序。 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: DlgInput 过程类似于:
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.因此,在 IDC_VALID 情况下,我想检查单选按钮的值,我尝试使用 GetDlgItem function 但我真的不明白它返回什么值。 I saw that it's possible to use the BM_GETCHECK message but I'm not sure how to use it.
我看到可以使用 BM_GETCHECK 消息,但我不确定如何使用它。 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?有人可以向我解释一下单选按钮是如何工作的吗?
You could try to send the BM_GETCHECK message to the control and check the return value.您可以尝试将BM_GETCHECK 消息发送到控件并检查返回值。 And you will need the HWND of your control, to get that from the control ID, you could try to call GetDlgItem() .
而且您将需要控件的 HWND,要从控件 ID 中获取它,您可以尝试调用GetDlgItem() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.