Well, harumph. Explains that anyway!
Printable View
Well, harumph. Explains that anyway!
I had a PrintPreview. I borrowed Printer.hdc and scaled all margins (cm) and Coordinates (e.g. Printer 600dip vs screen 96 dpi, read by GetDeviceCaps API, so ratioX is 600/96=6.25) then drew everything on hMetaDC.
'Preview Form: picPaper is a PictureboxCode:Dim hMetaDC As Long
hMetaDC = CreateEnhMetaFile(lhPrinterDC, vbNullString, rct, "gdiApp")
renderPage hMetaDC
If MFHdl Then DeleteEnhMetaFile MFHdl: MFHdl = 0
MFHdl = CloseEnhMetaFile(hMetaDC)
DeleteDC hMetaDC
Works just fine.Code:Private Sub picPaper_Paint()
Dim rc As RECT
picPaper.AutoRedraw = True
picPaper.Cls
GetClientRect picPaper.hWnd, rc
If MFHdl Then
PlayEnhMetaFile picPaper.hdc, MFHdl, rc
End If
picPaper.Refresh
picPaper.AutoRedraw = False
End Sub
If I don't get a top left on a monitor I then go for the nearest as a second resort........
but it's unusual for anyone to drop a window with the top left corner NOT on the monitor they want!Code:Function GetMonNo&(Frm As Form)
Dim xx&, yy&, RetVal&
'---------
RetVal = -1
'--------Try top left corner first
yy = MonitorFromPoint&(Frm.Left \ TPPX, Frm.Top \ TPPY, 2)
For xx = 0 To UBound(MonData)
If yy = MonData(xx).Handle Then
RetVal = xx
Exit For
End If
Next xx
If RetVal <> -1 Then
GetMonNo = RetVal
Exit Function
End If
'.......................top left not on a window, use nearest
yy = MonitorFromWindow&(Frm.hWnd, 2)
For xx = 0 To UBound(MonData)
If yy = MonData(xx).Handle Then
RetVal = xx
End If
Next xx
GetMonNo = RetVal
End Function
It's nice to see all you "heavy-lifters" were right on top of this DPI Awareness madness right when it was first introduced more than 9 years ago. I have just decided to bite the bullet and try to see what's all the hubbub since 1080p resolution is slowly becoming obsolete and losing more and more ground to 2k and 4k monitors.
It seems that the scaling factor provided by "WM_DPICHANGED" is quite enough to resize a form with a simple interface (no calculations needed for Screen.TwipsPerPixel that may produce rounding errors like I've read in previous posts). Of course, I'm quite new at this and may miss something in the bigger picture.
Nevertheless I have written a small Per-Monitor DPI Aware demo which seems to work fine in the scenarios where I was able to test it (100%, 125%, 150% and 175% scaling modes).