⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adddlg.cpp

📁 半成品具有添加
💻 CPP
字号:
// AddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ex_Student.h"
#include "AddDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddDlg dialog


CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddDlg)
	m_strGrade = _T("");
	m_strID = _T("");
	m_strName = _T("");
	m_fScore = 0.0f;
	m_intAge = 0;
	//}}AFX_DATA_INIT
}


void CAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddDlg)
	DDX_Control(pDX, IDC_SPIN_SCORE, m_spinScore);
	DDX_Control(pDX, IDC_SPIN_AGE, m_spinAge);
	DDX_CBString(pDX, IDC_COMBO_GRADE, m_strGrade);
	DDX_Text(pDX, IDC_EDIT_ID, m_strID);
	DDV_MaxChars(pDX, m_strID, 12);
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDV_MaxChars(pDX, m_strName, 8);
	DDX_Text(pDX, IDC_EDIT_SCORE, m_fScore);
	DDV_MinMaxFloat(pDX, m_fScore, 0.f, 100.f);
	DDX_Text(pDX, IDC_EDIT_AGE, m_intAge);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddDlg, CDialog)
	//{{AFX_MSG_MAP(CAddDlg)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_SCORE, OnDeltaposSpinScore)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_AGE, OnDeltaposSpinAge)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddDlg message handlers
BOOL CAddDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
    m_spinAge.SetRange(0,100);
	m_spinScore.SetRange(0,100);
	m_intAge=20;
	m_strSex="男";
	m_strGrade="计算机科学与技术071";

	CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1);
    if(m_bToModify==1)
	{
		SetWindowText("修改学生信息");
		CWnd *pWnd=GetDlgItem(IDC_EDIT_ID);
		pWnd->EnableWindow(FALSE);
		if(m_strSex=="女")
			CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO2);
	    else
		    CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1);
	}
	// TODO: Add extra initialization here
    UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CAddDlg::OnDeltaposSpinScore(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_fScore+=(float)pNMUpDown->iDelta*0.5f;
	if(m_fScore<0.0)
		m_fScore=0.0f;
	if(m_fScore>100.0)
		m_fScore=100.0f;
	UpdateData(FALSE);
	*pResult = 0;
}

void CAddDlg::OnDeltaposSpinAge(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}



void CAddDlg::OnRadio1() 
{
	m_strSex="男";
	// TODO: Add your control notification handler code here
	
}

void CAddDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	m_strSex="女";
}

void CAddDlg::OnOK() 
{
	// TODO: Add extra validation here
    UpdateData();
	 m_strID.TrimLeft();
	 if(m_strID.IsEmpty())
	 { MessageBox("请填写学生学号!","错误",MB_ICONERROR);return;}
	 m_strID.TrimLeft();
     if(m_strID.GetLength()!=12)
	 { MessageBox("学生学号必须由12位数字构成!","提示",MB_ICONINFORMATION);return;}
	 m_strName.TrimLeft();
     if(m_strName.IsEmpty())
	 {MessageBox("请填写学生姓名!"," 错误",MB_ICONERROR);return;}
else
	CDialog::OnOK();
}




void CAddDlg::SetToModify(bool bToModify)
{
	m_bToModify=bToModify;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -