📄 demodlg.cpp
字号:
// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ValidationRules.h"
#include "DemoDlg.h"
#include "DrawDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemoDlg)
m_nX = 0;
m_nY = 0;
m_nShape = -1;
//}}AFX_DATA_INIT
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
// 1 - Standard Class-Wizard-generated stuff
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
DDX_Control(pDX, IDC_SHAPE, m_cmbShape);
DDX_Control(pDX, IDC_Y, m_edtY);
DDX_Control(pDX, IDC_X, m_edtX);
DDX_Text(pDX, IDC_X, m_nX);
DDX_Text(pDX, IDC_Y, m_nY);
DDX_CBIndex(pDX, IDC_SHAPE, m_nShape);
//}}AFX_DATA_MAP
// 2 - Here come our custom validation rules
if( m_nShape == CDrawDoc::SQUARE )
{
// 3 - Validate "100 < X < 300"
pDX->PrepareEditCtrl( IDC_X );
DDV_MinMaxInt( pDX, m_nX, 100, 300 );
// 4 - Validate "100 < Y < 300"
pDX->PrepareEditCtrl( IDC_Y );
DDV_MinMaxInt( pDX, m_nY, 100, 300 );
}
else
{
// 5 - Validate "0 < X < 100"
pDX->PrepareEditCtrl( IDC_X );
DDV_MinMaxInt( pDX, m_nX, 0, 100 );
// 6 - Validate "0 < Y < 100"
pDX->PrepareEditCtrl( IDC_Y );
DDV_MinMaxInt( pDX, m_nY, 0, 100 );
// 7 - Validate "Y >= X" (custom validation)
pDX->PrepareEditCtrl( IDC_Y );
if( pDX->m_bSaveAndValidate && m_nY < m_nX )
{
// 8 - Display error message to the user
CString prompt;
prompt.Format( "Error: Y (%d) should be greater than X (%d).",
m_nY, m_nX );
AfxMessageBox( prompt, MB_ICONEXCLAMATION );
prompt.Empty(); // exception prep
// 9 - Fail the validation
pDX->Fail(); // note: throws a CUserException
}
}
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -