ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 445|回复: 4

[求助] 请教如何取得屏幕缩放比例(32位DLL拟在64位使用)

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-4-25 17:44 | 显示全部楼层 |阅读模式
1682415718701.png
32位的DLL在用activex.exe调用时,屏幕所取信息不正确,目前判断是因为屏幕缩放比例,不知如何取得?
请教高手!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-4-25 18:04 来自手机 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 thtfzhaobo 于 2023-4-25 18:11 编辑

其实主要问题是用vb被取得的坐标1280×720。实际上我的屏幕是1920的,大家也能看出来。常规用GetDeviceCaps 等取的都是1280。定应第1个坐标点的left和top属性都有所漂移。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-4-25 23:58 来自手机 | 显示全部楼层
thtfzhaobo 发表于 2023-4-25 18:04
其实主要问题是用vb被取得的坐标1280×720。实际上我的屏幕是1920的,大家也能看出来。常规用GetDeviceCaps ...

做了个系数修正一下,关贴,谢谢关注。

TA的精华主题

TA的得分主题

发表于 2023-4-27 03:18 | 显示全部楼层
  1. Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
  2. Private Declare PtrSafe Function MonitorFromWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal dwFlags As Long) As LongPtr
  3. Private Declare PtrSafe Function GetMonitorInfo Lib "user32" Alias "GetMonitorInfoA" (ByVal hMonitor As LongPtr, ByRef lpmi As Any) As Long
  4. Private Declare PtrSafe Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As Any) As Boolean
  5. Private Declare Function GetActiveWindow Lib "user32" () As LongPtr

  6. Private Type RECT
  7.     Left As Long
  8.     Top As Long
  9.     Right As Long
  10.     Bottom As Long
  11. End Type

  12. Private Type MONITORINFOEX
  13.     cbSize As Long
  14.     rcMonitor As RECT
  15.     rcWork As RECT
  16.     dwFlags As Long
  17.     szDevice As String * 32
  18. End Type

  19. Type DevMode
  20.     dmDeviceName(0 To 31) As Byte
  21.     dmSpecVersion As Integer
  22.     dmDriverVersion As Integer
  23.     dmSize As Integer
  24.     dmDriverExtra As Integer
  25.     dmFields As Long
  26.     dmOrientation As Integer
  27.     dmPaperSize As Integer
  28.     dmPaperLength As Integer
  29.     dmPaperWidth As Integer
  30.     dmScale As Integer
  31.     dmCopies As Integer
  32.     dmDefaultSource As Integer
  33.     dmPrintQuality As Integer
  34.     dmColor As Integer
  35.     dmDuplex As Integer
  36.     dmYResolution As Integer
  37.     dmTTOption As Integer
  38.     dmCollate As Integer
  39.     dmFormName(0 To 31) As Byte
  40.     dmLogPixels As Integer
  41.     dmBitsPerPel As Long
  42.     dmPelsWidth As Long
  43.     dmPelsHeight As Long
  44.     dmDisplayFlagsUnion As Long ' Union member: 'dmNup' or 'dmDisplayFlags'
  45.     dmNup As Long ' Union member: 'dmNup' or 'dmDisplayFlags'
  46. End Type
  47. Public Function GetScreenScale() As Double

  48.     Dim hMonitor As LongPtr
  49.     hMonitor = MonitorFromWindow(GetActiveWindow, 0&)
  50.    
  51.     Dim miex As MONITORINFOEX: miex.cbSize = Len(miex)
  52.     Call GetMonitorInfo(hMonitor, miex)
  53.    
  54.     Dim dm As DevMode: dm.dmSize = Len(dm)
  55.     Call EnumDisplaySettings(miex.szDevice, -1&, dm)
  56.    
  57.     Dim cxLogical As Long: cxLogical = (miex.rcMonitor.Right - miex.rcMonitor.Left)
  58.     Dim cyLogical As Long: cyLogical = (miex.rcMonitor.Bottom - miex.rcMonitor.Top)
  59.    
  60.     Dim cxPhysical As Long: cxPhysical = dm.dmPelsWidth
  61.     Dim cyPhysical As Long: cyPhysical = dm.dmPelsHeight
  62.    
  63.     GetScreenScale = ((cxPhysical / cxLogical) + (cyPhysical / cyLogical)) / 2#
  64. End Function
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-4-28 13:18 | 显示全部楼层
感谢,这个结果一样,都是与ActiveWindow.ActivePane.PointsToScreenPixelsX取得不符
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-17 05:36 , Processed in 0.044039 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表