c# - 如何在任何打开的窗口中获取鼠标下的文本

标签 c# winapi mouseover

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

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

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

非常感谢您的合作。

最佳答案

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

this answer 中的建议所以,

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.

所以试着在那个方向找点东西。

关于c# - 如何在任何打开的窗口中获取鼠标下的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6384562/

相关文章:

C# EndsWith 有时会给出错误结果

c# - 具有通配符属性的 Specflow 步骤定义映射

windows - CreateProcessAsUser 错误代码 6

c# - 带有脚本的Unity音频错误

c++ - 在 C++ 中将 .h 文件包含到 Win32 api 时出错

c++ - 如何正确销毁窗口?

html - 客户 X 或 ClientY 必须像带有他的号码的像素一样被读取。我不知道在哪里添加它而不给出语法错误

javascript - 在传单 map 上捕获 d3 中的鼠标悬停

jquery - 在鼠标悬停时更改 css 类

c# - 什么时候为 WPF/MVVM 使用事件和命令?