'代码出处:http://www.yulv.net/archives/99/
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
'获取当前屏幕分辨率
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
'获取当前屏幕所有支持的分辨率
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
'设置当前屏幕分辨率
Dim DevM As DEVMODE
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Sub Form_Load()
Dim a As Boolean
Dim b As Integer
Do
a = EnumDisplaySettings(0&, b, DevM)
b = b + 1
List1.AddItem DevM.dmPelsWidth & "*" & DevM.dmPelsHeight
Loop Until (a = False)
'---------------------------------------------------------------获取当前屏幕所有支持的分辨率
Dim x As String
Dim y As String
x = CStr(GetSystemMetrics(SM_CXSCREEN))
y = CStr(GetSystemMetrics(SM_CYSCREEN))
Me.Caption = "当前分辨率为: " & x & "*" & y
'---------------------------------------------------------------获取当前屏幕分辨率
End Sub
Private Sub List1_DblClick()
Dim x As Integer
Dim y As Integer
x = Val(Split(List1.List(List1.ListIndex), "*")(0))
y = Val(Split(List1.List(List1.ListIndex), "*")(1))
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = x
DevM.dmPelsHeight = y
ChangeDisplaySettings DevM, 0
'---------------------------------------------------------------设置当前屏幕分辨率
End Sub