0

I want to take a screenshot of the user's currently active window (and run OCR on top of it at a later stage). This (e.g. described here) works fine as long as the developer works on standard monitors with the same resolution.

The problem is, that WPF uses device-independent units and the native API functions require pixels. I found many resources how to fix this for my own WPF application, most prominantly here and here. However, I found no way to do this dependent on what monitor the window is currently shown. For example, if the developer has a laptop with a QHD dipslay and uses a secondary monitor with a normal HD resolution. I found a C++ solution on MSDN, but not in C#.

Does anyone have experience with this or any suggestions? Thanks.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
casaout
  • 1,819
  • 3
  • 24
  • 54
  • You don't need to use native functions. You'll find several SO questions that ask how to capture a screenshot. The answer is to get the screen's Graphics object and copy its contents to a bitmap using .NET Graphic commands – Panagiotis Kanavos Apr 23 '15 at 09:23
  • BTW why OCR? You can use the accessibility APIs to get the contents of all visible windows. If an accessibility utility can do access the kind of information you want, so can your code. – Panagiotis Kanavos Apr 23 '15 at 09:25
  • Yes, I can do a screenshot of the current window. And I found out how to get the dpiX and dpiY value from Graphics.FromHwnd(...). But, this only does it for one monitor and not the one where the currently active window is on... – casaout Apr 23 '15 at 09:27
  • I tried that too, but without success, see my SO question here: http://stackoverflow.com/questions/29796974/get-the-content-of-any-active-window Thanks. – casaout Apr 23 '15 at 09:27
  • 1
    You can get all screens with [Screen.AllScreens](https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens%28v=vs.110%29.aspx) then copy the contents one-by-one. – Panagiotis Kanavos Apr 23 '15 at 09:29
  • thanks. And can I find out on what screen the currently active Window is on? – casaout Apr 23 '15 at 09:32
  • btw, talking about accessing windows' content via accessibility apis: do you maybe have a link/tutorial? I didn't find something from that I could successfully use... Thank you! – casaout Apr 23 '15 at 09:36

0 Answers0