无法捕获子类编辑框控件的 VK_RETURN 键

发布于 2024-08-01 23:15:08 字数 922 浏览 2 评论 0原文

我对编辑框控件进行了子类化,例如

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-08-08 23:15:08

不,系统使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文