以类class CDummyEdit : public CEditView为例:
1) 在.h中添加:
// Generated message map functions
protected:
//{{AFX_MSG(CDummyEdit)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
2).Cpp中添加:
BEGIN_MESSAGE_MAP(CDummyEdit, CEditView)
//{{AFX_MSG_MAP(CDummyEdit)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CDummyEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if( (nChar == 'a') || ( nChar == 'A') )
{
short nKeyState = GetKeyState(VK_CONTROL);
BOOL bCtrlCKeyDown = nKeyState & 0x80;
if(bCtrlCKeyDown)// Key is down
{
GetEditCtrl().SetSel( 0, -1);
}
}
CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}
阅读(2165) | 评论(0) | 转发(0) |