我使用以下代码: Private Sub Form_Load() ResWidth = Screen.Width \ Screen.TwipsPerPixelX ResHeight = Screen.Height \ Screen.TwipsPerPixelY ScreenRes = ResWidth "x" ResHeight MsgBox (ScreenRes)End Sub 还有其他几个类似的代码我
Private Sub Form_Load() ResWidth = Screen.Width \ Screen.TwipsPerPixelX ResHeight = Screen.Height \ Screen.TwipsPerPixelY ScreenRes = ResWidth & "x" & ResHeight MsgBox (ScreenRes) End Sub
还有其他几个类似的代码我用Google搜索过.问题是,我总是得到一个消息框说我的分辨率是1200×1200,虽然我的实际分辨率是1920×1200.为什么我的成绩不好?
不确定为什么不起作用,但您可以使用Windows API.Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long
然后,当您需要屏幕宽度和高度时,请定义以下常量:
Private Const SM_CXSCREEN = 0 Private Const SM_CYSCREEN = 1
然后,您可以在任何需要的地方使用GetSystemMetrics.如果将声明和常量添加到模块(.BAS)更有意义,那么只需声明声明和常量.
Dim width as Long, height as Long width = GetSystemMetrics(SM_CXSCREEN) height = GetSystemMetrics(SM_CYSCREEN)
GetSystemMetrics on Microsoft Support