MFC的CEdit控件中实现复制、粘贴、剪切等操作的快捷键

今天在一个MFC的GUI程序中实现了一个自定义的列表控件类(CListCtrl),在这个类里嵌入了一个CEdit类以便于编辑列表项,为了实现在编辑每个列表项时能支持快捷键,在派生的CEdit类加入下面这个函数:

  1. BOOL CCustomizedListCtrl::CListEditor::PreTranslateMessage(MSG* pMsg)  
  2. {  
  3.     // 编辑框快捷键操作   
  4.     if(WM_KEYDOWN == pMsg->message)   
  5.     {  
  6.         if(::GetFocus() == m_hWnd && (GetKeyState( VK_CONTROL) & 0xFF00 ) == 0xFF00)   
  7.         {  
  8.             // 全选   
  9.             if( pMsg->wParam == 'A' || pMsg->wParam == 'a')  
  10.             {  
  11.                 this->SetSel(0, -1);  
  12.                 return true;  
  13.             }  
  14.   
  15.             // 拷贝   
  16.             if( pMsg->wParam == 'C' || pMsg->wParam == 'c')  
  17.             {  
  18.                 this->Copy();  
  19.                 return true;  
  20.             }  
  21.   
  22.             // 剪切   
  23.             if( pMsg->wParam == 'X' || pMsg->wParam == 'x')  
  24.             {  
  25.                 this->Cut();  
  26.                 return true;  
  27.             }  
  28.   
  29.             // 粘贴   
  30.             if( pMsg->wParam == 'V' || pMsg->wParam == 'v')  
  31.             {  
  32.                 this->Paste();  
  33.                 return true;  
  34.             }  
  35.   
  36.             // 粘贴   
  37.             if( pMsg->wParam == 'Z' || pMsg->wParam == 'z')  
  38.             {  
  39.                 this->Undo();  
  40.                 return true;  
  41.             }  
  42.   
  43.         }  
  44.     }  
  45.   
  46.     return CEdit::PreTranslateMessage(pMsg);  
  47. }  

 

一开始实现时,编辑列表项不能捕捉焦点,后在google代码搜索中搜关键字PreTranslateMessage,才知道没加一个判断条件,::GetFocus() == m_hWnd。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值