C#中,检测到选定的文本上的窗口? [英] C# , detect selected text on windows?

查看:118
本文介绍了C#中,检测到选定的文本上的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会做一个工具,像谷歌工具栏翻译功能,但它是桌面。
我想要做的是什么
强调在任何应用程序(文字,PDF,淘宝旺旺等)的文本,并通过谷歌翻译翻译API,回报作为工具提示。

I would make a tools like Google toolbar translate function, but it is for desktop. What i want to do is highlight the text in any application (word,pdf,live messenger etc) , and translate by google translate api ,return as a tool tips.

我有搜索MSDN有关监视的文字,我只能用复制和放大器发现;粘贴和监视剪贴板打勾事件

I have search msdn about monitoring text, i only found using copy&paste and monitoring clipboard to tick the event.

所以,任何想法关于那个?
你的感谢。

so, any idea about that? thanks you.

推荐答案

一个起点,将获取到当前前台窗口的引用。下面的代码将获得当前选定的窗口和窗口的标题:

A starting point would be to get a reference to the current foreground window. The code below will get the currently selected window and the title of that window:

[ DllImport("user32.dll") ]

static extern int GetForegroundWindow();

[ DllImport("user32.dll") ]
static extern int GetWindowText(int hWnd, StringBuilder text, int count); 

private void GetActiveWindow()
{

const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);

   handle = GetForegroundWindow();

   if ( GetWindowText(handle, Buff, nChars) > 0 )
   {
   this.captionWindowLabel.Text = Buff.ToString();
   this.IDWindowLabel.Text = handle.ToString();
   }

}

您可以运行中的这段代码定时器:即给用户10秒内选择一个窗口

You could run this code within a timer: i.e give the user 10 seconds to select a window.

我不知道你将如何检索窗口中选定的文本,但我会考虑它为您

I am not sure how you would retrieve selected text within a window, but I will look into it for you.

这篇关于C#中,检测到选定的文本上的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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