Page 2 of 2 FirstFirst 12
Results 41 to 44 of 44

Thread: [RESOLVED] Per-Monitor DPI Awareness & VB

  1. #41
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Per-Monitor DPI Awareness & VB

    Well, harumph. Explains that anyway!

  2. #42
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [RESOLVED] Per-Monitor DPI Awareness & VB

    Quote Originally Posted by dilettante View Post
    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.

  3. #43
    Addicted Member
    Join Date
    Jul 2006
    Posts
    159

    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.

  4. #44
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,644

    Red face 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).

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width