www.pudn.com > Shutdown.rar > Y_Cls_Edit_.cpp
// Y_Cls_Edit_.cpp : implementation file
//
#include "stdafx.h"
#include "Y_Cls_Edit_.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Y_Cls_Edit_
//Move style after press enter key
#define M_LEFT 1 //移动方向
#define M_BOTTOM 2
Y_Cls_Edit_::Y_Cls_Edit_()
{
m_character_ctrl = 1; //输入字符标志位1为有效字符,0为无效字符
m_MoveStyle =1;//回车后移动方式,1向右,2向下
}
Y_Cls_Edit_::~Y_Cls_Edit_()
{
}
BEGIN_MESSAGE_MAP(Y_Cls_Edit_, CEdit)
//{{AFX_MSG_MAP(Y_Cls_Edit_)
ON_WM_KEYDOWN()
ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Y_Cls_Edit_ message handlers
void Y_Cls_Edit_::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == '1'||nChar== '2'||nChar== '3'||nChar== '4'||nChar== '5'||nChar== '6'||nChar== '7'||
nChar == '8'||nChar== '9'||nChar== '0'||nChar == 189||nChar == 190||
nChar == VK_SUBTRACT||
nChar == VK_DECIMAL||
nChar == VK_NUMPAD0||
nChar == VK_NUMPAD1||
nChar == VK_NUMPAD2||
nChar == VK_NUMPAD3||
nChar == VK_NUMPAD4||
nChar == VK_NUMPAD5||
nChar == VK_NUMPAD6||
nChar == VK_NUMPAD7||
nChar == VK_NUMPAD8||
nChar == VK_NUMPAD9||
nChar == VK_BACK
)
m_character_ctrl=1;
else if(nChar ==VK_ESCAPE)
{
::PostMessage(this->GetParent()->m_hWnd,WM_KEYDOWN,WPARAM(nChar),LPARAM(0));
::PostMessage(this->GetParent()->m_hWnd,WM_KEYUP,WPARAM(nChar),LPARAM(0));
return;
}
else if(nChar == VK_LEFT ||
nChar == VK_UP ||
nChar ==VK_RIGHT ||
nChar == VK_DOWN)
{
this->GetWindowRect(m_rect);
this->GetParent()->ScreenToClient(m_rect);
m_pt = m_rect.CenterPoint();
switch(nChar)
{
case VK_LEFT:
m_pt.x=m_rect.left-2;
break;
case VK_UP:
m_pt.y=m_rect.top-2;
break;
case VK_RIGHT:
m_pt.x=m_rect.right+2;
break;
case VK_DOWN:
m_pt.y =m_rect.bottom+2;
break;
}
m_lp=MAKELPARAM(m_pt.x,m_pt.y);
::PostMessage(this->GetParent()->m_hWnd,WM_LBUTTONDOWN ,(WPARAM)MK_LBUTTON,m_lp);
::PostMessage(this->GetParent()->m_hWnd,WM_LBUTTONUP, (WPARAM)MK_LBUTTON,m_lp);
// ::SetCursorPos(m_pt.x,m_pt.y);
}
else
m_character_ctrl=0;
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
void Y_Cls_Edit_::OnUpdate()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CEdit::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
CString str;
if(m_character_ctrl!=1)
{
m_character_ctrl=1;
SetWindowText("");
}
// TODO: Add your control notification handler code here
}
//回车移动
BOOL Y_Cls_Edit_::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)
{
this->GetWindowRect(m_rect);
m_pt = m_rect.CenterPoint();
if(m_MoveStyle==M_LEFT)
m_pt.x=m_rect.right+2;
else if(m_MoveStyle==M_BOTTOM)
{
m_pt.y += m_rect.Height();
}
else
m_pt.x=m_rect.right+2;
if(pMsg->wParam ==VK_RETURN)
{
m_lp=MAKELPARAM(m_pt.x,m_pt.y);
::PostMessage(this->GetParent()->m_hWnd,WM_LBUTTONDOWN ,(WPARAM)MK_LBUTTON,m_lp);
::PostMessage(this->GetParent()->m_hWnd,WM_LBUTTONUP, (WPARAM)MK_LBUTTON,m_lp);
::SetCursorPos(m_pt.x,m_pt.y);
}
}
return CEdit::PreTranslateMessage(pMsg);
}