vb.net - 获取辅助屏幕的缩放因子
问题描述
我想获得辅助屏幕的比例因子。
使用这段代码,我可以获得主监视器的正确信息:
Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal nIndex As Integer) As Integer
Private Declare Function GetDCEx Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hrgnClip As IntPtr, ByVal DeviceContextValues As DeviceContextValues) As IntPtr
Dim desktop As IntPtr = GetDCEx(0, 0, DeviceContextValues.Window)
Dim scalling As Double = GetDeviceCaps(desktop, 118) / GetDeviceCaps(desktop, 8)
但是我怎样才能获得第二台显示器的相同信息呢?
GetDCEx 函数中有哪些参数?
解决方案
谢谢它对我的帮助,这是解决方案:
<DllImport("gdi32.dll")>
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("gdi32.dll", SetLastError:=True, CharSet:=CharSet.Ansi)>
Public Shared Function CreateDC(<MarshalAs(UnmanagedType.LPStr)> lpszDriver As String,
<MarshalAs(UnmanagedType.LPStr)> lpszDevice As String,
<MarshalAs(UnmanagedType.LPStr)> lpszOutput As String,
lpInitData As IntPtr) As IntPtr
End Function
Public Shared Function GetScalleFactor(index As Integer) As Double
Dim desktop As IntPtr = CreateDC(Screen.AllScreens(index).DeviceName, Nothing, Nothing, IntPtr.Zero)
Return GetDeviceCaps(desktop, 118) / GetDeviceCaps(desktop, 8)
End Function
推荐阅读
- django - 调整图像大小以在 django 中更快地加载
- python - (Python, Flask) Flask 路由函数由于 IO 绑定耗时太长,所以客户端超时
- ios - 用于企业应用的 UIPasteboard
- python - Python:将集合列表转换为带有索引的字典
- c# - 在 WPF 中运行 Livecharts 时 CartesianChart 的垂直轴出现问题
- python - 如何将相似的列表聚集在一起?
- powershell - 配置 Elasticsearch
- xamarin.forms - 为什么我的 PHP 网站没有收到我从 Android Xamarin 应用程序发送 POST 的变量?
- splunk - Splunk:如何启用 Splunk SSO
- scala - 在火花结构化流中,有没有办法在数据库维护窗口期间休眠读取操作