WM_KEYDOWN怎么吃钥匙 [英] How to eat keys in WM_KEYDOWN

查看:31
本文介绍了WM_KEYDOWN怎么吃钥匙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理编辑框中的 WM_KEYDOWN 消息.
我正在处理一堆键,但对于某些键(例如选项卡),我想防止将可显示字符附加到编辑框.

Im handling the WM_KEYDOWN message in an edit box.
I am handling a bunch of keys, but for certain keys (eg. tab) i'd like to prevent the displayable character from being appended to the editbox.

case WM_KEYDOWN:
    {
        switch(wParam)
        {
        case VK_TAB:
            //handle tab here
            //Eat tab key
            return 0;
        default:
            return DefWndProc(hwnd,message,wParam,lParam);
        }
     }
     break;

我可以检测和删除 WM_KEYUP 消息中的选项卡,但使用这种方法,选项卡键明显地从编辑框中添加和删除.

I can detect and delete the tab in WM_KEYUP message, but with this method the tab key is visibly added and removed from the edit box.

WM_KEYDOWN 有没有吃钥匙的方法?

is there any way of eating a key in WM_KEYDOWN?

推荐答案

  1. 覆盖PreTranslateMessage 在你的对话类中.
  2. 如果 MSG 参数的 messageWM_KEYDOWNwParamVK_TABhwnd 是您的编辑控件,处理它并简单地返回 TRUE.
  1. Override PreTranslateMessage in your dialog class.
  2. If the MSG parameter's message is WM_KEYDOWN and the wParam is VK_TAB and the hwnd is that of your edit control, handle it and simply return TRUE.

返回 TRUE 意味着该事件已被处理,因此不会被 CEdit 控件处理.

Returning TRUE means that that event has already been processed and thus will not be processed by the CEdit control.

这篇关于WM_KEYDOWN怎么吃钥匙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆