Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1028010
  • 博文数量: 288
  • 博客积分: 10306
  • 博客等级: 上将
  • 技术积分: 3182
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-12 17:00
文章分类

全部博文(288)

文章存档

2011年(19)

2010年(38)

2009年(135)

2008年(96)

我的朋友

分类: C/C++

2009-07-28 14:49:03

以类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);
}
阅读(2117) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~