16,473
社区成员
发帖
与我相关
我的任务
分享
// MyEdit.h : header file
#pragma once
// CMyEdit window
class CMyEdit : public CEdit
{
DECLARE_DYNAMIC(CMyEdit)
// Construction
public:
CMyEdit();
virtual ~CMyEdit();
// Attributes
protected:
BOOL m_bAutoClearFlag;
virtual BOOL PreTranslateMessage(MSG* pMsg);
};
// MyEdit.cpp : implementation file
//
#include "stdafx.h"
#include "MyEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyEdit
IMPLEMENT_DYNAMIC(CMyEdit, CEdit)
CMyEdit::CMyEdit()
{
m_bAutoClearFlag = TRUE;
}
CMyEdit::~CMyEdit()
{
}
/////////////////////////////////////////////////////////////////////////////
// CMyEdit message handlers
BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN)
{
if(m_bAutoClearFlag) //需要清除?
{
SetWindowText(_T(""));
m_bAutoClearFlag = FALSE;
}
if(pMsg->wParam == VK_RETURN) //回车
{
m_bAutoClearFlag = TRUE;
}
}
return CEdit::PreTranslateMessage(pMsg);
}
#include "MyEdit.h"
class CDlgTest10Dlg : public CDialog
{
protected:
CMyEdit m_MyEdit;
virtual void OnOK();
……
};
void CDlgTest10Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgTest10Dlg)
DDX_Control(pDX, IDC_EDIT1, m_MyEdit);
//}}AFX_DATA_MAP
}
void CDlgTest10Dlg::OnOK()
{
CString szInput;
m_MyEdit.GetWindowText(szInput);
AfxMessageBox(szInput);
//CDialog::OnOK();
}