如何在任何打开的窗口中用鼠标获取文本 [英] How to get text under mouse in any open window

查看:79
本文介绍了如何在任何打开的窗口中用鼠标获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#语言开发一个项目.我想制作一个类似于Narcis或Easylingo的字典,该字典使用户能够使用鼠标并在任何应用程序中将光标移到WORD上,然后程序会检测到该单词并找到该特定单词的含义.

我的问题是如何在任何应用程序(例如Microsoft Office或Web浏览器等)中检测到屏幕上鼠标光标下的单词.

我正在寻找可以帮助我的任何提示和指南或任何代码.

非常感谢您的合作.

解决方案

您将需要弄弄Win API来捕获将文本输出到屏幕的GDI调用.

此答案

通常,对于GDI控件,您可以获取控件的位置和大小,并且通常可以获取字体信息.例如,使用静态文本控件您将使用 WM_GETFONT .然后,一旦有了鼠标,就可以获得相对于控件位置的鼠标位置,并使用其中一种字体功能,例如 解决方案

You will need to fiddle with Win API capture the GDI calls that output text to the screen.

As suggested in this answer on SO,

Usually for GDI controls you can get the position and size of the control, and you can usually get the font info. For example, with static text controls you'd use WM_GETFONT. Then once you have that you can get the position of the mouse relative to the position of the control and use one of the font functions, perhaps something like GetTextExtentPoint32 to figure out what is under the cursor.

So try finding something in that direction.

这篇关于如何在任何打开的窗口中用鼠标获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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