📄 radiobuttondlg.cpp
字号:
// RadioButtonDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RadioButton.h"
#include "RadioButtonDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonDlg dialog
CRadioButtonDlg::CRadioButtonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRadioButtonDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRadioButtonDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRadioButtonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRadioButtonDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRadioButtonDlg, CDialog)
//{{AFX_MSG_MAP(CRadioButtonDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonDlg message handlers
BOOL CRadioButtonDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CRadioButtonDlg::OnButton1()
{
// 暂时隐藏主对话框
ShowWindow(SW_HIDE);
UINT nSex=GetCheckedRadioButton(IDC_SEX1,IDC_SEX2); // 获得性别选择
UINT nAge=GetCheckedRadioButton(IDC_AGE1,IDC_AGE4); // 获得年龄选择
CString msg="sex: "; // 保存输出消息字符串
// 根据用户的选择生成消息串
// 添加性别信息
switch (nSex)
{
case IDC_SEX1:
msg+="man\n";
break;
case IDC_SEX2:
msg+="woman\n";
break;
default:
break;
}
// 添加年龄信息
msg+="age: ";
switch (nAge)
{
case IDC_AGE1:
msg+="10-19 years old";
break;
case IDC_AGE2:
msg+="20-29 years old";
break;
case IDC_AGE3:
msg+="30-39 years old";
break;
case IDC_AGE4:
msg+="40-49 years old";
break;
default:
break;
}
msg+="\n\nOK?";
// 显示输入消息框询问用户所输入的信息是否正确
if(MessageBox(msg,NULL,MB_YESNO|MB_ICONQUESTION)==IDNO)
{
// 当用户回答"否"时重新显示对话框以供便用户可以更改所作的选择
ShowWindow(SW_SHOW);
return;
}
// 否则退出应用程序
CDialog::OnOK();
}
void CRadioButtonDlg::OnButton2()
{
::PostQuitMessage(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -