以扫码枪回车作为区分, 下次输入时自动清除
// MyEdit.h : header file
#pragma once
#define WM_MYINPUT_MSG (WM_USER + 1000)
/////////////////////////////////////////////////////////////////////////////
// CMyEdit window
class CMyEdit : public CEdit
{
DECLARE_DYNAMIC(CMyEdit)
// Construction
public:
CMyEdit();
virtual ~CMyEdit();
public:
BOOL m_bPostMessageMode; //消息模式?
// Attributes
protected:
BOOL m_bAutoClearFlag; //自动清除标记
protected:
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;
//消息模式?
//消息模式时,回车时将给父窗口发送WM_MYINPUT_MSG消息
//非消息模式,回车时父窗口将收到IDOK点击消息
m_bPostMessageMode = TRUE;
}
CMyEdit::~CMyEdit()
{
}
/////////////////////////////////////////////////////////////////////////////
// CMyEdit message handlers
BOOL CMyEdit:reTranslateMessage(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; //标记为下次清除
if(m_bPostMessageMode) //消息模式
{
//检查输入非空时发送消息给父窗口
CString szInput;
GetWindowText(szInput);
CWnd *pParent = GetParent();
if(pParent && (!szInput.IsEmpty()))
{
WPARAM wParam = GetDlgCtrlID(); //控件ID
LPARAM lParam = (LPARAM)m_hWnd; //控件窗口句柄
pParent->ostMessage(WM_MYINPUT_MSG, wParam, lParam);
}
//阻止继续生成IDOK消息
return TRUE;
}
}
}
return CEdit:reTranslateMessage(pMsg);
} |