Results 1 to 5 of 5

Thread: [RESOLVED] GetSystemMetricsForDpi alternative

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    603

    Resolved [RESOLVED] GetSystemMetricsForDpi alternative

    GetSystemMetrics is an old API w/o DPIAware. GetSystemMetricsForDpi does. But GetSystemMetricsForDpi is a newer API for above Windows 10 Anniversary version 1607. Is there any way to replace by a method to get the right things like VScrollbar Width? Or Is it not meanness for older than Win10 1607 because previous system is not real PerMonitorV2 at all?

    Code:
    gVariables.gVScrollbarWidth = NativeMethods.GetSystemMetricsForDpi(2, DeviceDpi)
    Code:
    gVariables.gVScrollbarWidth = NativeMethods.GetSystemMetrics(2)
    Code:
    <DllImport("user32", SetLastError:=True)>
    Public Shared Function GetSystemMetricsForDpi(ByVal nIndex As Integer, ByVal dpi As Integer) As Integer
    Last edited by DaveDavis; Jun 25th, 2022 at 07:53 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: GetSystemMetricsForDpi alternative

    You could use the SystemInformation Class...

    SystemInformation.VerticalScrollBarWidth

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    603

    Re: GetSystemMetricsForDpi alternative

    Quote Originally Posted by .paul. View Post
    You could use the SystemInformation Class...

    SystemInformation.VerticalScrollBarWidth
    SystemInformation.VerticalScrollBarWidth is the same with GetSystemMetrics(2). From what I tested, it fails to get the right value in some situation (e.g. Main display is 168, 2nd is 96 Dpi). I even multiply a sgnScaleFactor, but hard to give correct sgnScaleFactor.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    603

    Re: GetSystemMetricsForDpi alternative

    GetSystemMetrics(2) always returns the main display screen data. GetSystemMetricsForDpi has 2nd parameter DeviceDpi to do computation. It is useful when the window moved to the 2nd Monitor.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    603

    Re: GetSystemMetricsForDpi alternative

    I got it:
    1. While app launching, read the main screen Dpi by gInitMainScreenDpiX= NativeMethods.GetDeviceCaps(desktopDC, 88) and set VScrollbar.Width = NativeMethods.GetSystemMetrics(2)
    2. While app move to another screen, VScrollbar.Width = GetSystemMetrics(2) * CurrentDeviceDpi / gInitMainScreenDpiX

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