0

I'm using this answer to get an external process dimension (using Process.MainWindowHandle and GetWindowRect\DwmGetWindowAttribute functions Pinvoke).

But I need to get the dimension of the window excluding any other process\window that hiding part\all of this process, in other words, only the visible area of this MainWindowsHandle.

For example, how do I get only the red dashed area of Explorer.exe and VNC.exe in this screenshot?

example

Community
  • 1
  • 1
  • It requires pinvoke. Consider explaining why this is important so somebody can propose a better approach. – Hans Passant Apr 25 '17 at 15:08
  • 1
    I had the same issue 1,5 year ago and what I did was to enumerate all HWND's based on their `Z` position on the screen. At the end you just have to subtract overlapped rects from the one you're needing. – mrogal.ski Apr 25 '17 at 15:13
  • @HansPassant I already use Pinvoke as mentioned, to get the window dimension. So I can use other WinApi functions as well. The reason I need to do that is to prompt the user if part of the application is covered by other window\menu even though it's still in front (which I determine by using GetForegroundWindow) and mark the problematic area. – ShugiShugi Apr 25 '17 at 15:24
  • 1
    @m.rogalski Thanks. I've tried to do so based on this http://stackoverflow.com/a/27067603/7919921 , apparently, I had to run my process elevated so I can access another process internal handles, and it looks kind of unreliable, I got wrong Z order (even though my process was covered by unfocused windows, it was first in Z order) – ShugiShugi Apr 25 '17 at 15:30
  • I perhaps ought to point out a flaw in that master-plan. "mark the problematic area" requires painting. Painting requires a window. In other words, you have to put a window with a transparent background on top of these windows. That's possible, but the flaw is that this creates the very problem you are trying to solve :) – Hans Passant Apr 25 '17 at 15:44
  • @HansPassant That what I already do (: I have a transparent win form over the window (using Form Region and Region.Exclude proprety). I know how to ignore my process when I check which process is in front and etc. All I have to do now is to 'include' the problematic area, so it can paint this area, so that why I ask if anyone got a creative solution for that. – ShugiShugi Apr 25 '17 at 15:55

0 Answers0