📄 dialogmodal.cpp
字号:
// DialogModal.cpp : implementation file
//
#include "stdafx.h"
#include "Dialog.h"
#include "DialogModal.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogModal dialog
CDialogModal::CDialogModal(CWnd* pParent /*=NULL*/)
: CDialog(CDialogModal::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogModal)
m_Edit = _T("");
//}}AFX_DATA_INIT
}
void CDialogModal::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogModal)
DDX_Control(pDX, IDC_COMBO, m_Combo);
DDX_Control(pDX, IDC_SEX1, m_Radio);
DDX_Text(pDX, IDC_EDIT, m_Edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogModal, CDialog)
//{{AFX_MSG_MAP(CDialogModal)
ON_BN_CLICKED(ID_OK, OnOk)
ON_BN_CLICKED(ID_CANCEL, OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogModal message handlers
BOOL CDialogModal::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Radio.SetCheck(1); //把"男"设置为默认值
m_Combo.InsertString(0,"小学");//往Combo Box加入选项
m_Combo.InsertString(1,"初中");
m_Combo.InsertString(2,"高中");
m_Combo.InsertString(3,"大学");
m_Combo.InsertString(4,"本科以上...");
m_Combo.SetCurSel(0);//把"小学"设置为默认值
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialogModal::OnOk()
{
// TODO: Add your control notification handler code here
CString str;
str.Empty();//
if(m_Radio.GetCheck())
str += "先生";
else
str += "小姐";
str += "你好,你的爱好:";
BOOL flag=0;
CButton *p;
//得到指向IDC_INSTEREST1的指针
p = (CButton *)GetDlgItem(IDC_INSTEREST1);
if(p->GetCheck())//判断"登山"是否被选中
{
str += "登山 ";
flag = 1;
}
//得到指向IDC_INSTEREST2的指针
p = (CButton *)GetDlgItem(IDC_INSTEREST2);
if(p->GetCheck())//判断"游泳"是否被选中
{
str += "游泳 ";
flag = 1;
}
//得到指向IDC_INSTEREST3的指针
p = (CButton *)GetDlgItem(IDC_INSTEREST3);
if(p->GetCheck())//判断"看书"是否被选中
{
str += "看书 ";
flag = 1;
}
//得到指向IDC_INSTEREST4的指针
p = (CButton *)GetDlgItem(IDC_INSTEREST4);
if(p->GetCheck())//判断"玩游戏"是否被选中
{
str += "玩游戏 ";
flag = 1;
}
if (!flag)
str += "不知道";
str += ",学历:";
int number;
CString temp;
number = m_Combo.GetCurSel();//得到当前被选中项的序号
m_Combo.GetLBText(number,temp);//得到序号为number的项的內容
str += temp;
m_Edit = str;
UpdateData(false);//更新文本框中的内容
}
void CDialogModal::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();//退出模态对话框
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -