NO

Author Topic: GetMonitorInfo and MONITORINFOEX  (Read 3682 times)

reachjeffs

  • Guest
GetMonitorInfo and MONITORINFOEX
« on: November 02, 2019, 05:51:26 PM »
I have a knack for missing the obvious, so I'll apologize in advance if there's a simple solution.

I'm trying to wrap my head around DPI scaling on multiple displays in Win10.  In this particular case, I'm not trying to make my own application DPI aware.  I'm working with a context menu shell extension, and simply need to know the scaling of the monitor the Explorer window (or maybe the menu itself) is displayed on.  I realize there may eventually be more detection needed, but right now I'm trying to take a simple approach to see how well it works.  I believe the approach in option 2 of the accepted answer at this link is where I want to start...
https://stackoverflow.com/questions/33507031/detect-if-non-dpi-aware-application-has-been-scaled-virtualized

The problem is, I can't get this portion to compile:
Code: [Select]
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);

MONITORINFOEX miex;
miex.cbSize = sizeof(miex);
GetMonitorInfo(hMonitor, &miex);
int cxLogical = (miex.rcMonitor.right  - miex.rcMonitor.left);
int cyLogical = (miex.rcMonitor.bottom - miex.rcMonitor.top);

I end up with error #2140: Type error in argument 2 to 'GetMonitorInfoA'; expected 'LPMONITORINFO' but found 'LPMONITORINFOEXA'. 

If I understand correctly, I should be able to use MONITORINFO or MONITORINFOEX with GetMonitorInfo, but it will only compile if I use MONITORINFO.  And since the linked approach above uses szDevice from MONITORINFOEX, the MONITORINFO structure simply doesn't contain the value I need.  So, for starters, I just want to know if I'm missing a simple step that should allow this code to compile.

Of course, I'm wide open to suggestions of a better way to find scaling on a specific display.  So we can ignore everything above and skip to a better solution if anyone already has one.

Thanks everyone,
Jeff

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2144
Re: GetMonitorInfo and MONITORINFOEX
« Reply #1 on: November 02, 2019, 06:40:06 PM »
just cast it
Code: [Select]
GetMonitorInfo(hMonitor, (LPMONITORINFO)&miex);
May the source be with you

reachjeffs

  • Guest
Re: GetMonitorInfo and MONITORINFOEX
« Reply #2 on: November 02, 2019, 06:55:46 PM »
just cast it
Code: [Select]
GetMonitorInfo(hMonitor, (LPMONITORINFO)&miex);

Thanks for the quick response.  Dang, I could've sworn I already tried casting and it didn't work.  But, seems to be working now.  I knew it would be simple.  Thanks again!