C #, define selected text in windows?

I would make tools like the google toolbar translation feature, but this is for the desktop. What I want to do is select the text in any application (word, pdf, live messenger, etc.) and translate it into google translate api, return it as a hint.

I have a msdn search for control text, I found that I just copied and copied the clipboard to mark this event.

so, any idea about this? thanks.

+3
source share
3 answers

The starting point would be to get a link to the current foreground window. The code below will get the currently selected window and the title of this 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 , .

, , .

+3

, , , . , InteropServices , .

Windows API.

0

, , , , , .

, , , , winapi, , , , - . , , ... , CodeProject , , , .NET 1.0.

, , , .

0

Source: https://habr.com/ru/post/1724001/


All Articles