子类化编辑控件时正确处理VK_DELETE

时间:2014-03-16 06:37:37

标签: c++ winapi subclassing editcontrol

我将编辑控件子类化为仅接受十进制数字。

一切正常,唯一剩下的就是当用户选择部分文字并按Delete键(VK_DELETE)时处理案例。

我的问题如下:

Delete键(VK_DELETE)会发送一些消息,例如WM_CLEAR我可以用于处理,或者我必须在子类中处理WM_KEYDOWN程序并在那里进行处理?

谢谢。

最好的问候。

1 个答案:

答案 0 :(得分:1)

在记事本的编辑控件上运行Spy ++之后,我得出结论WM_KEYDOWN / WM_KEYUP就是你得到的。

<000001> 0015082E S WM_KILLFOCUS hwndGetFocus:0015082E
<000002> 0015082E R WM_KILLFOCUS
<000003> 0015082E S WM_SETFOCUS hwndLoseFocus:002D0830
<000004> 0015082E R WM_SETFOCUS
<000005> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000006> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000007> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000008> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000009> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000010> 0015082E P WM_KEYDOWN nVirtKey:VK_DELETE cRepeat:1 ScanCode:53 fExtended:1 fAltDown:0 fRepeat:0 fUp:0
<000011> 0015082E P WM_KEYUP nVirtKey:VK_DELETE cRepeat:1 ScanCode:53 fExtended:1 fAltDown:0 fRepeat:1 fUp:1
<000012> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000013> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000014> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000015> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000016> 0015082E P message:0x0118 [Unknown] wParam:0000FFFF lParam:FFFFF960001DA744
<000017> 0015082E S EM_GETSEL lpdwStart:0020F330 lpdwEnd:0020F334
<000018> 0015082E R EM_GETSEL wStart:2 wEnd:2 lpdwStart:0020F330 (2) lpdwEnd:0020F334 (2)
<000019> 0015082E S WM_KILLFOCUS hwndGetFocus:(null)
<000020> 0015082E R WM_KILLFOCUS

相关行是<000010><000011>WM_KEYDOWNWM_KEYUP是背对背的。根本没有调用WM_CLEAR。那里的一条有趣的0x0118消息,但是每次按键都显示,而不仅仅是删除键。