下面的示例说明如何创建并使用样例 GetScreenResolution() 函数。
备注:您可能有某些在现有 Microsoft Access 库中定义的 Microsoft Windows API 函数;因此,您的声明可能被重复。如果您收到重复过程名称错误消息,请在代码中删除或注释出声明语句。
新建模块,然后键入下列“声明”和函数:
'*****************************************************************
' DECLARATIONS SECTION
'*****************************************************************
Option Explicit
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
' NOTE: The following declare statements are case sensitive.
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" _
(ByVal hWnd As Long, rectangle As RECT) As Long
'*****************************************************************
' 函数: GetScreenResolution()
'
' 目的:
' 来确定当前屏幕的大小或分辨率
'
' 返回:
' 当前屏幕分辨率,下列为典型值:
' 640 x 480
' 800 x 600
' 1024 x 768
'
'*****************************************************************
Function GetScreenResolution () as String
Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long
hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function
|
在视图菜单上,单击立即窗口。
在“立即窗口”中键入下行命令,然后按 ENTER 键:
注意:当前屏幕分辨率显示在“立即窗口”中。如果当前分辨率是标准 VGA,则在“立即”窗口中显示下列内容: