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

📄 valid.cpp

📁 This companion disc contains the source code for the sample programs presented in INSIDE VISUAL C++
💻 CPP
字号:
// valid.cpp
//
#include "stdafx.h"
#include "valid.h"

BEGIN_MESSAGE_MAP(CValidDialog, CDialog)
	//{{AFX_MSG_MAP(CValidDialog)
	ON_MESSAGE(WM_VALIDATE, OnValidate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CValidDialog::CValidDialog(UINT ID) : CDialog(ID)
{
	TRACE("CValidDialog ctor\n");
    m_bValidationOn = TRUE;                      // turn validation on
}

void CValidDialog::ValidateDlgItem(CDataExchange* pDX, UINT ID)
{
	// return valid unless overridden in the dialog
	ASSERT(this);
	TRACE("CValidDialog::ValidateDlgItem (should be overridden)\n");
	return;
}


BOOL CValidDialog::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// specific for WIN32 -- wParam/lParam processing different for WIN16
 	TRACE("CValidDialog::OnCommand, wParam = %x, lParam = %x\n", wParam, lParam);
	TRACE("m_bValidationOn = %d\n", m_bValidationOn);
	if(m_bValidationOn) {   // might be a killfocus
        UINT notificationCode = (UINT) HIWORD( wParam );
        if((notificationCode == EN_KILLFOCUS)  ||
           (notificationCode == LBN_KILLFOCUS) ||
           (notificationCode == CBN_KILLFOCUS) ) {
            CWnd* pFocus = CWnd::GetFocus();
            // if we're changing focus to another control in the same dialog
            if( pFocus && (pFocus->GetParent() == this) ){
            	if(pFocus->GetDlgCtrlID() != IDCANCEL) {
            	    // and focus not in Cancel button
                    // validate AFTER drawing finished
                	PostMessage(WM_VALIDATE, wParam);
				}
            }
        }
    }
	return CDialog::OnCommand(wParam, lParam); // pass it on
}


LONG CValidDialog::OnValidate(UINT wParam, LONG lParam)
{
	TRACE("Entering CValidDialog::OnValidate\n");
	CDataExchange dx(this, TRUE);
    m_bValidationOn = FALSE;               // temporarily off
    UINT controlID = (UINT) LOWORD( wParam );
	try {
	    ValidateDlgItem(&dx, controlID);
	}
	catch(CUserException* pUE) {
		pUE->Delete();
		TRACE("caught the exception\n");
		// fall through -- user already alerted via message box
	}
    m_bValidationOn = TRUE;
    return 0;                            // goes no further
}

⌨️ 快捷键说明

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