|
-
Aug 16th, 2015, 10:38 AM
#41
Re: [RESOLVED] Per-Monitor DPI Awareness & VB
Well, harumph. Explains that anyway!
-
Aug 16th, 2015, 11:08 AM
#42
Frenzied Member
Re: [RESOLVED] Per-Monitor DPI Awareness & VB
 Originally Posted by dilettante
Each time VB high DPI scaling errors in ScaleX, ScaleY, and friends comes up I walk away and then smack my head again. Surely this isn't new and has been encountered and somehow dealt with long ago with printers, where high DPI values have been common for a very long time?
Aside from the multi-monitor thing none of this should be new... should it? Or did we all just ignore it for printed output?
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.
Code:
Dim hMetaDC As Long
hMetaDC = CreateEnhMetaFile(lhPrinterDC, vbNullString, rct, "gdiApp")
renderPage hMetaDC
If MFHdl Then DeleteEnhMetaFile MFHdl: MFHdl = 0
MFHdl = CloseEnhMetaFile(hMetaDC)
DeleteDC hMetaDC
'Preview Form: picPaper is a Picturebox
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
Works just fine.
Last edited by Jonney; Aug 16th, 2015 at 11:12 AM.
-
Aug 16th, 2015, 11:54 AM
#43
Addicted Member
Re: [RESOLVED] Per-Monitor DPI Awareness & VB
If I don't get a top left on a monitor I then go for the nearest as a second resort........
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
but it's unusual for anyone to drop a window with the top left corner NOT on the monitor they want!
Last edited by JohnTurnbull; Aug 16th, 2015 at 12:01 PM.
-
Aug 20th, 2023, 11:15 PM
#44
Re: [RESOLVED] Per-Monitor DPI Awareness & VB
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).
Last edited by VanGoghGaming; Oct 13th, 2023 at 04:17 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|