#include "stdafx.h" #include ".\trapkeyedit.h" CTrapKeyEdit::CTrapKeyEdit(void) { isEnterKey = false; isLButton = false; m_bFocusFlag = false; //isNumber = false; } CTrapKeyEdit::~CTrapKeyEdit(void) { } BEGIN_MESSAGE_MAP(CTrapKeyEdit, CEdit) ON_WM_GETDLGCODE() ON_WM_KEYUP() ON_WM_LBUTTONUP() ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus) END_MESSAGE_MAP() UINT CTrapKeyEdit::OnGetDlgCode() { return DLGC_WANTARROWS|DLGC_WANTALLKEYS|DLGC_WANTCHARS; } void CTrapKeyEdit::DispatchEventEN_CHANGE() { HWND parent = GetParent()->m_hWnd; int ctrl = GetDlgCtrlID(); ::SendMessage( parent, WM_COMMAND, MAKEWPARAM(ctrl, EN_CHANGE), (LPARAM) m_hWnd); } // process/detect keystrokes, dispatch events to alert base class void CTrapKeyEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { //UINT nCharNew; //Check if the key pressed was a DOWN ARROW key //if (nChar == VK_LBUTTON) // AfxMessageBox("It is a left button press!"); //if (nChar == VK_DOWN) // AfxMessageBox("It is a down arrow key!"); //if (nChar == VK_RIGHT) // AfxMessageBox("It is a right arrow key!"); //if (nChar == VK_LEFT) // AfxMessageBox("It is a left arrow key!"); //if (nChar == VK_UP) // AfxMessageBox("It is a up arrow key!"); if (nChar == VK_RETURN) // AfxMessageBox("It is a enter key!"); { isEnterKey = true; DispatchEventEN_CHANGE(); //nCharNew = VK_TAB; // AfxMessageBox("It is a enter key!"); } //if ((nChar >= '0') && (nChar <= '9')) //{ // isNumber = true; // DispatchEventEN_CHANGE(); //} CEdit::OnKeyUp(nChar, nRepCnt, nFlags); // pass on the info to the base class } void CTrapKeyEdit::OnLButtonUp(UINT nFlags, CPoint point) { CEdit::OnLButtonUp(nFlags, point); int nStartChar, nEndChar; if (!m_bFocusFlag) { GetSel(nStartChar, nEndChar); SetSel(nStartChar, nEndChar); } m_bFocusFlag = true; if (!isLButton && GetModify()) { isLButton = true; DispatchEventEN_CHANGE(); } //AfxMessageBox("It is a left button press!"); } void CTrapKeyEdit::OnKillfocus() { m_bFocusFlag = false; }