无法捕获子类编辑框控件的 VK_RETURN 键
我对编辑框控件进行了子类化,例如
lpfnOldWndProc = (FARPROC)SetWindowLong(hEdit,GWL_WNDPROC, (DWORD)SubClassFunc);
LRESULT FAR PASCAL SubClassFunc( HWND hWnd,
UINT Message,
WPARAM wParam,
LPARAM lParam)
{
switch(Message)
{
case WM_CHAR:
//Process this message to avoid message beeps.
if ((wParam == VK_RETURN) || (wParam == VK_TAB))
{
//Do Something
return 0;
}
break;
case WM_KEYDOWN:
if ((wParam == VK_RETURN) || (wParam == VK_TAB)) {
//Do Something
return 0;
}
break ;
default:
break;
}
return CallWindowProc((WNDPROC)lpfnOldWndProc, hWnd, Message, wParam, lParam);
}
现在,当我在编辑框中输入 char 时,会调用该子类化过程。 但是当按下回车键时我无法得到它。
上面的程序有问题吗?
I subclassed an edit box control like
lpfnOldWndProc = (FARPROC)SetWindowLong(hEdit,GWL_WNDPROC, (DWORD)SubClassFunc);
LRESULT FAR PASCAL SubClassFunc( HWND hWnd,
UINT Message,
WPARAM wParam,
LPARAM lParam)
{
switch(Message)
{
case WM_CHAR:
//Process this message to avoid message beeps.
if ((wParam == VK_RETURN) || (wParam == VK_TAB))
{
//Do Something
return 0;
}
break;
case WM_KEYDOWN:
if ((wParam == VK_RETURN) || (wParam == VK_TAB)) {
//Do Something
return 0;
}
break ;
default:
break;
}
return CallWindowProc((WNDPROC)lpfnOldWndProc, hWnd, Message, wParam, lParam);
}
Now when I enter char in editbox this subclassed procedure gets called. But I am not able to get it when enter key is pressed.
Is this something wrong in above procedure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,系统使用 WM_GETDLGCODE 来确定控件感兴趣的按键按下。默认情况下,编辑框不处理 Return(对话框过程将其解释为按下默认按钮),因此不需要将 VK_RETURNS 发送到它。 您需要处理 WM_GETDLGCODE 消息并返回 DLGC_WANTALLKEYS,然后您应该得到 VK_RETURNS。
MS 文档很好地概述了这种子分类场景。
No, the system uses WM_GETDLGCODE to determine which key presses the control is interested in. By default a edit box doesn't process Return (the dialog procedure interprets it as pressing the default button) and therefore doesn't require that VK_RETURNS are sent to it. You need to process the WM_GETDLGCODE message and return DLGC_WANTALLKEYS then you should get your VK_RETURNS.
The MS documentation outlines this sub-classing scenario pretty well.