Private Sub Command1_Click() MsgBox CStr(Screen.Height \ Screen.TwipsPerPixelY) '屏幕高度 MsgBox CStr(Screen.Width \ Screen.TwipsPerPixelX) '屏幕宽度 End Sub不用api,这样就可以
这样有的机器会出现问题的,所以必须要用api得到.
用api实现的例子。Option Explicit Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long Const HORZRES = 8 Const VHORZRES = 10 Const BITSPIXEL = 12 Private Sub Command1_Click() Dim H As Long, V As Long, Color As Long H = GetDeviceCaps(Form1.hdc, HORZRES) '屏幕宽度 V = GetDeviceCaps(Form1.hdc, VHORZRES) '屏幕高度 Color = GetDeviceCaps(Form1.hdc, BITSPIXEL) '屏幕颜色位数 MsgBox "当前分辨率为:" + CStr(H) + "*" + CStr(V) + "," + CStr(Color) + "位色"
MsgBox CStr(Screen.Height \ Screen.TwipsPerPixelY) '屏幕高度
MsgBox CStr(Screen.Width \ Screen.TwipsPerPixelX) '屏幕宽度
End Sub不用api,这样就可以
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Const HORZRES = 8
Const VHORZRES = 10
Const BITSPIXEL = 12
Private Sub Command1_Click()
Dim H As Long, V As Long, Color As Long
H = GetDeviceCaps(Form1.hdc, HORZRES) '屏幕宽度
V = GetDeviceCaps(Form1.hdc, VHORZRES) '屏幕高度
Color = GetDeviceCaps(Form1.hdc, BITSPIXEL) '屏幕颜色位数
MsgBox "当前分辨率为:" + CStr(H) + "*" + CStr(V) + "," + CStr(Color) + "位色"
End Sub
TwipsPerPixelX和TwipsPerPixelY的调用不会出现问题呀,没必要用api