|
获取系统分辨率用下面一个api够了,不过不清楚和你的方法(GetDeviceCaps)有什么区别。
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
SYSWIDTH = GetSystemMetrics(0) ' x轴方向
SYSHEIGHT = GetSystemMetrics(1) ' y轴方向
然后通过下面api函数获取窗体的左上右下四个方向的值
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
=============
下面的例子稍作修改就可获得Piexl和Point的相互转换关系
'将窗体移动至屏幕中心
'先加入一个窗体,并设置属性StartupPosition=3(启动时的默认位置,即左上角)
'将上面的API声明复制到窗体声明部分
'窗体Initialize事件中加入下面代码
Dim hwnd&
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption) 'XL97
Else
hwnd = FindWindow("ThunderDFrame", Me.Caption) 'XL2000
End If
Dim SYSWIDTH&, SYSHEIGHT&, Size As RECT
Dim nWidth&, nHeight&
SYSWIDTH = GetSystemMetrics(0)
SYSHEIGHT = GetSystemMetrics(1)
GetWindowRect hwnd, Size '获取窗体尺寸 单位为像素
'移动窗口到屏幕中心
MoveWindow hwnd, (SYSWIDTH - Size.Right) / 2, (SYSHEIGHT - Size.Bottom) / 2, _
Size.Right, Size.Bottom, False
======
上例中excel中磅和像素之间对应关系为:Me.Width ~ size.Right
不知道说的对不对,请高人指正。 |
|