1

I'm looking for a way to identify if a handle references something on the/a screen (a screen, a window, a control, the entire virtual desktop, etc).

I'm trying to standardise the resolution of the interface so that I can consistently save it and do non-regression testing on it. So I've hooked a couple of system calls like GetDeviceCaps so that I can intercept the resolution and change it to a consistent 96DPI.

So far I've found GetObjectType that doesn't necessarily tell me if the object is part of the screen (comparing to OBJ_DC and OBJ_MemDC). Combining that with WindowFromDC I can get a slightly more indicative result, but it's still not perfect.

I thought maybe I could use EnumDisplayMonitors with null for the first two parameters, but it never seems to function.

Does anyone have a fool proof way of telling if a handle references a screen object or not?

Thank you in advance! Loren

dakotapearl
  • 373
  • 1
  • 15
  • User objects, gdi objects.., pretty mixed up. Not to mention there is no such thing as as a screen object. And why would EnumDisplayMonitors tell you if an arbitrary handle is a window handle or not? Your question is not clear at all.. – Sertac Akyuz Jul 04 '19 at 15:19
  • It's a pretty vast problem. I suppose that's why it's not as clear as I'd like it to be. For EnumDisplayMonitors I imagined finding the rect of thing to drawn (to a screen or a printer or something else) and compare it using this system call since it returns instances based on intersection, but I can't get consist results – dakotapearl Jul 04 '19 at 15:24
  • Thanks, I can't follow that so I'm passing on EnumDisplayMonitors. I can't follow the rest similarly, you can't pass a *control handle* to GetDeviceCaps, so why would you try to find out if it's in fact a window handle? You can find out if a DC is for a display device by calling GetDeviceCaps. – Sertac Akyuz Jul 04 '19 at 20:33

1 Answers1

1

Turns out I could've used GetDeviceCaps with the parameter index set to TECHNOLOGY. An object related to rendering to a screen will be identified as DT_RASDISPLAY

See https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps

dakotapearl
  • 373
  • 1
  • 15
  • It should've turn out earlier, I've [commented](https://stackoverflow.com/questions/56889513/determine-if-a-handle-points-to-an-element-of-the-screen-and-not-a-printer-etc#comment100334183_56889513) that about nearly 2 months ago. – Sertac Akyuz Jul 30 '19 at 14:49
  • You're absolutely right, I don't know how I missed that. Sorry. If you want the points write a quick response and I'll accept it. Also sorry that I don't check back too often! :) – dakotapearl Sep 12 '19 at 06:38
  • No problems.. :) – Sertac Akyuz Sep 12 '19 at 15:31