实现方法
从CEdit派生出CEditEx类,并在CEditEx类中添加虚函数PreTranslateMessage,添加如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
BOOL CEditEx::PreTranslateMessage(MSG* pMsg)
{
// 编辑框快捷键操作
if (WM_KEYDOWN == pMsg->message)
{
if (::GetFocus() == m_hWnd && (GetKeyState(VK_CONTROL) & 0xFF00) == 0xFF00)
{
// 全选
if (pMsg->wParam == 'A' || pMsg->wParam == 'a')
{
SetSel(0, -1);
return TRUE;
}
// 拷贝
if (pMsg->wParam == 'C' || pMsg->wParam == 'c')
{
Copy();
return TRUE;
}
// 剪切
if (pMsg->wParam == 'X' || pMsg->wParam == 'x')
{
Cut();
return TRUE;
}
// 粘贴
if (pMsg->wParam == 'V' || pMsg->wParam == 'v')
{
Paste();
return TRUE;
}
// 撤销
if (pMsg->wParam == 'Z' || pMsg->wParam == 'z')
{
Undo();
return TRUE;
}
}
}
return CEdit::PreTranslateMessage(pMsg);
}
接着将EditEx.h文件设为预编译头文件,供所有类使用,于是便可以在自己的窗口类中声明CEditEx控件,使用Create等方法创建支持快捷键的文本框,也可以在可视化编辑中对文本框添加控件型关联变量,将变量类型改为CEditEx(其实关联变量会帮助进行SubClassWindow)
原文链接
原文链接:https://blog.csdn.net/tonnychu/article/details/19334221?utm_source=blogxgwz2,有更改