子类化编辑控件时正确处理VK_DELETE [英] Properly handle VK_DELETE when subclassing edit control

查看:66
本文介绍了子类化编辑控件时正确处理VK_DELETE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



一切正常,剩下的就是处理用户选择部分时的情况文本并按删除键( VK_DELETE )。



我的问题如下:



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



谢谢。



祝你好运。

I am subclassing edit control to accept only decimal numbers.

Everything works fine, and the only thing left for me is processing the case when user selects portion of the text and presses Delete key ( VK_DELETE ).

My question is following:

Does pressing a Delete key ( VK_DELETE ) sends some message like WM_CLEAR that I can use for my processing, or do I have to handle WM_KEYDOWN in my subclassing procedure and do the processing there?

Thank you.

Best regards.

推荐答案

评论中解释的细节比问题本身更重要,你没有告诉我们最重要的事情。问题纯粹是人为的,这是它的根源:这将被存储为0.123456789,它比允许的最大值更长。也就是说,您是表示数据库中数字的字符串。这是完全错误的,浪费的,不可靠的。您需要存储数字类型的数据。一般来说,这是一个奇怪的趋势,这些日子困扰着许多初学者:使用代表数据而不是数据本身的字符串。这非常糟糕。



当然,在用户界面中,你最好过滤掉不需要的字符。例如,如果输入小数数据,您可能只需要允许数字,十进制分隔符(请记住,这取决于文化!),以及可选+或 - (您可能希望根据允许的范围进行设置),以及退格。这种过滤是常规技术。我不认为这对你来说是一个问题。



至于处理 VK_DELETE ,你不是需要做任何事情,但默认。请看我对这个问题的评论。



-SA
The detail explained in your comment are more important than the question itself, where you did not tell us the most important things. The problem is purely artificial, and here is the root of it: "This will be stored as 0.123456789 which is longer than maximal allowed". That said, you are string strings representing numbers in the database. This is totally wrong, wasteful, unreliable. You need to store data of numeric types. Generally, this is a weird trend haunting many beginners these days: working with strings representing data instead of data itself. This is very bad.

And of course, in the UI, you should better filter out unwanted characters. For example, if you enter fractional data, you may need to allow only digits, decimal delimiter (remember, it depends on culture!) and, optionally + or - (you may want to make it depending on the allowed range), and also backspace. This filtering is the routine techniques. I don't think this is a problem for you.

As to handling VK_DELETE, you don't need to do anything but default. Please see my comment to the question.

—SA


这篇关于子类化编辑控件时正确处理VK_DELETE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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