Xojo Conferences
XDCMay2019MiamiUSA

[MBS] ScreenshotRectMBS and HighDPI Windows Apps (MBS Xojo Plugin Mailinglist archive)

Back to the thread list
Previous thread: [MBS] [ANN] 16.0pr6
Next thread: [MBS] [ANN] MBS Xojo Conference 2016 in Koblenz, Germany


[MBS] MBS 7.5 with RB2010r4.1   -   Garth Hjelte
  [MBS] ScreenshotRectMBS and HighDPI Windows Apps   -   Michael Diehr
   Re: [MBS] ScreenshotRectMBS and HighDPI Windows Apps   -   Christian Schmitz

[MBS] ScreenshotRectMBS and HighDPI Windows Apps
Date: 13.01.16 04:56 (Tue, 12 Jan 2016 19:56:52 -0800)
From: Michael Diehr
I'm finding that in Windows 10, the call

dim p as picture = ScreenshotRectMBS(self.left,self.top,self.width,self.height)

is returning the wrong area of the screen, when running on a display that is not set at 100% scale factor.

My guess is that your call is using physical pixels rather than logical pixels?

The fix should be just to ask Windows what the scaling factor is and then adjust the coordinates.

Easy, right?

Not so- many of the APIs lie to you about the dpi scaling.

For example

Dim dpiX As Integer = GetDeviceCaps(hdc, LOGPIXELSX)

Always returns 96

I found one answer that seems to work:

// see http://stackoverflow.com/questions/5977445/how-to-get-windows-display-settings

Declare Function GetDC Lib "user32" (hWnd As Integer) As Ptr
Declare Function GetDeviceCaps Lib "gdi32" (hdc As Ptr, nIndex As Integer) As Integer
Declare Sub ReleaseDC Lib "user32" (hWnd As Integer, hdc As Ptr)

const VERTRES = 10
const DESKTOPVERTRES = 117

Dim hdc As Ptr = GetDC(self.Handle)
Dim logicalHeight As Integer = GetDeviceCaps(hdc, VERTRES)
Dim physicalHeight As Integer = GetDeviceCaps(hdc, DESKTOPVERTRES)
ReleaseDC(hwnd, hdc)

Dim scaleFactor As Double = physicalHeight/logicalHeight

dim p as picture = ScreenshotRectMBS(self.left* scaleFactor,self.top* scaleFactor,self.width* scaleFactor,self.height* scaleFactor)

// the picture may be an odd size, so resize the picture if needed


_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] ScreenshotRectMBS and HighDPI Windows Apps
Date: 13.01.16 09:22 (Wed, 13 Jan 2016 09:22:41 +0100)
From: Christian Schmitz

> My guess is that your call is using physical pixels rather than logical pixels?

probably.

> The fix should be just to ask Windows what the scaling factor is and then adjust the coordinates.
>
> Easy, right?

sounds right.

>
> I found one answer that seems to work:

Thanks.

Sincerely
Christian