-
Jun 25th, 2022, 07:49 AM
#1
Thread Starter
Fanatic Member
[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.
-
Jun 25th, 2022, 12:08 PM
#2
Re: GetSystemMetricsForDpi alternative
You could use the SystemInformation Class...
SystemInformation.VerticalScrollBarWidth
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 25th, 2022, 06:31 PM
#3
Thread Starter
Fanatic Member
Re: GetSystemMetricsForDpi alternative
Originally Posted by .paul.
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.
-
Jun 25th, 2022, 11:33 PM
#4
Thread Starter
Fanatic Member
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.
-
Jun 25th, 2022, 11:46 PM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|