?? 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 + -