Use VB to change the screen resolution and refresh frequency
Source: Internet
Author: User
Option Explicit
Public Declare Function ChangeDisplaySettings () Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA"
(ByRef lpDevMode As DEVMODE, ByVal dwFlags As Long) As Long
Public Declare Function EnumDisplaySettings () Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal
LpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As DEVMODE) As Long
Const DM_PELSHEIGHT As Long = & H100000
Const DM_PELSWIDTH As Long = & H80000
Const DM_BITSPERPEL As Long = & H40000
Const DM_DISPLAYFREQUENCY As Long = & H400000
Const CCHDEVICENAME As Long = 32
Const CCHFORMNAME As Long = 32
Const CDS_TEST = & H4
Private Type DEVMODE
DmDeviceName As String * CCHDEVICENAME
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 * cchformname
Dmunusedpadding as integer
Dmbitsperpel as integer
Dmpelswidth as long
Dmpelsheight as long
Dmdisplayflags as long
Dmdisplayfrequency as long
End type
''Timeout ''-------------------------------------------------------------------------------------------
''Lngwidth // screen width (in pixels)
''Lngheight // screen height (in pixels)
''Intcolor // Number of BITs (e. g 16 or 32)
''Lngfrequency // screen refresh frequency
''
''Declaration:
''When calling this function, make sure that the set value is within the range allowed by the system. For example, the maximum refresh frequency of the system is 80, and you
''Sets LngFrequency to 85, which will lead to unpredictable consequences.
''Timeout ''------------------------------------------------------------------------------------------
Public Function SetDisplaymode () Function SetDisplaymode (LngWidth As Long, LngHeight As Long, IntColor As Integer,
LngFrequency As Long) As Long
Dim NewDevmode As DEVMODE
Dim lngP As Long
''Obtains information
EnumDisplaySettings 0 &, 0 &, NewDevmode
With NewDevmode
. DmFields = DM_PELSHEIGHT Or DM_PELSWIDTH Or DM_BITSPERPEL Or DM_DISPLAYFREQUENCY
. DmPelsWidth = LngWidth
. DmPelsHeight = LngHeight
. DmBitsPerPel = IntColor
. DmDisplayFrequency = LngFrequency
End
SetDisplaymode = ChangeDisplaySettings (NewDevmode, CDS_TEST)
End Function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.