Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188051
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类: Windows平台

2014-02-12 23:22:09

Dpi_Ratio.BAS
---------------------------------------------

点击(此处)折叠或打开

  1. Option Explicit
  2. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  3. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

  4. Public DpiRatio As Single

  5. Public Sub DpiRatioIni()
  6.     Dim DPI As Long
  7.     DPI = GetDeviceCaps(GetDC(0), 88)
  8.     DpiRatio = 1440 / DPI / 15
  9. End Sub



FORM
--------------------------------------

点击(此处)折叠或打开

  1. Private Sub Form_Initialize()
  2.     On Error Resume Next
  3.     Call DpiRatioIni
  4.     If DpiRatio <> 1 Then
  5.         With Me
  6.             .Left = .Left * DpiRatio
  7.             .Width = .Width * DpiRatio
  8.             .Top = .Top * DpiRatio
  9.             .Height = .Height * DpiRatio
  10.             .FontSize = .FontSize * DpiRatio
  11.         End With
  12.         
  13.         Dim obj
  14.         For Each obj In Controls
  15.             With obj
  16.                 .Left = .Left * DpiRatio
  17.                 .Width = .Width * DpiRatio
  18.                 .Top = .Top * DpiRatio
  19.                 .Height = .Height * DpiRatio
  20.                 .FontSize = .FontSize * DpiRatio
  21.             End With
  22.         Next
  23.     End If
  24. End Sub

下面是另一段代码:


点击(此处)折叠或打开

  1. Option Explicit
  2. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Any) As Long
  3. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

  4. Private Sub Form_Initialize()
  5.     On Error Resume Next
  6.     Dim DC0 As Long, DPI As Long, DpiRatio As Single
  7.     DC0 = CreateDC("DISPLAY", vbNullString, vbNullString, 0)
  8.     DPI = GetDeviceCaps(DC0, 88)
  9.     If DPI <> 0 Then
  10.         DpiRatio = 1440 / DPI / 15
  11.         If DpiRatio <> 1 Then
  12.             With Me
  13.                 .Left = .Left * DpiRatio
  14.                 .Width = .Width * DpiRatio
  15.                 .Top = .Top * DpiRatio
  16.                 .Height = .Height * DpiRatio
  17.                 .FontSize = .FontSize * DpiRatio
  18.             End With
  19.             
  20.             Dim obj
  21.             For Each obj In Controls
  22.                 With obj
  23.                     .Left = .Left * DpiRatio
  24.                     .Width = .Width * DpiRatio
  25.                     .Top = .Top * DpiRatio
  26.                     .Height = .Height * DpiRatio
  27.                     .FontSize = .FontSize * DpiRatio
  28.                 End With
  29.             Next
  30.         End If
  31.     End If
  32. End Sub

阅读(445) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~