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

 

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

  • BOOL CCustomizedListCtrl::CListEditor::PreTranslateMessage(MSG* pMsg) 
  •     // 编辑框快捷键操作 
  •     if(WM_KEYDOWN == pMsg->message)  
  •     { 
  •         if(::GetFocus() == m_hWnd && (GetKeyState( VK_CONTROL) & 0xFF00 ) == 0xFF00)  
  •         { 
  •             // 全选 
  •             if( pMsg->wParam == 'A' || pMsg->wParam == 'a'
  •             { 
  •                 this->SetSel(0, -1); 
  •                 return true
  •             } 
  •  
  •             // 拷贝 
  •             if( pMsg->wParam == 'C' || pMsg->wParam == 'c'
  •             { 
  •                 this->Copy(); 
  •                 return true
  •             } 
  •  
  •             // 剪切 
  •             if( pMsg->wParam == 'X' || pMsg->wParam == 'x'
  •             { 
  •                 this->Cut(); 
  •                 return true
  •             } 
  •  
  •             // 粘贴 
  •             if( pMsg->wParam == 'V' || pMsg->wParam == 'v'
  •             { 
  •                 this->Paste(); 
  •                 return true
  •             } 
  •  
  •             // 粘贴 
  •             if( pMsg->wParam == 'Z' || pMsg->wParam == 'z'
  •             { 
  •                 this->Undo(); 
  •                 return true
  •             } 
  •  
  •         } 
  •     } 
  •  
  •     return CEdit::PreTranslateMessage(pMsg); 

 

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值