使用CDC :: TextOut/DrawText在控件上编写文本时,如何获取文本? [英] How to get text when a text is written on a control using CDC::TextOut/DrawText?

查看:124
本文介绍了使用CDC :: TextOut/DrawText在控件上编写文本时,如何获取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用CDC TextOut/DrawText编写文本,该如何排序GetWindowText?

How can I sort of a GetWindowText if the text was written using CDCs TextOut/DrawText?

推荐答案

绘制"的文本"不再是文字,但是图片.
要找到解决方案,您必须:

*避免这种情况,在绘制文本之前将其保留在原处
*尝试从绘制的图片中使用一些字符识别来找回文本.

最后一点与本机API无关(尽管有一些可以玩此游戏的特定Windows文本服务-只需在MSDN中搜索这些键或"OCR"),但需要更复杂的代码(为此也存在一些库)在任何情况下(就CPU使用率而言)都没有保留原始文本那么快和高效".

应该考虑更好的重新设计.除非您必须从其他窗口中猜测文本,否则您将无法使用它.
A "text" that is "drawn" is anymore a text, but is a picture.
To come to a solution you have to either:

* Avoid this situation, keeping somewhere the text as it is before it is drawn
* Try to get the text back using some character recognition from the drawn picture.

The last point is not something into the native API (although there are some specific windows text services that can play this game - just search MSDN for those keys or for "OCR") but require more complex code (some library also exist for that) that is is any case not as fast and "efficient" (in term of CPU usage) than keeping the original text.

A better re-design should be considered. Unless you have to guess the text from somebody else window you have no way to work with.


您现在无法轻松获得它,因为它现在已成为位图的一部分.一种方法是使用成员变量来保留使用TextOut呈现的文本.或者,如果它是所有者绘制控件,则使用SetWindowText并使用GetWindowText绘制文本.
You cannot get it easily because it is now part of the bitmap. One way would be to use a member variable to keep the text rendered using TextOut. Or use SetWindowText and use GetWindowText to draw the text if it is an owner-draw control.


嗯...由用户绘制的东西通常不是窗口的属性". ..

...但是您可以尝试使用自己的控件来子类化,
也会提供此类字符串属性及其访问权限...:)
Hm... a drawn by user thing is not a "property" of a window normally...

...but you could try to subclass a control by your own one,
which would provide such string property and its access too... :)


这篇关于使用CDC :: TextOut/DrawText在控件上编写文本时,如何获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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