Change Screen Resolution

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'The program will prompt to you if the computer must be restarted to apply changes.
'Insert the following code to your module:

Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1
Public Const DISP_CHANGE_FAILED = -1
Public Const DISP_CHANGE_BADMODE = -2
Public Const DISP_CHANGE_NOTUPDATED = -3
Public Const DISP_CHANGE_BADFLAGS = -4
Public Const DISP_CHANGE_BADPARAM = -5
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H2
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public 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
Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, ByVal iModeNum As Long, _
lpDevMode As Any) As Boolean
Declare Function ChangeDisplaySettings Lib "user32" Alias _
"ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

'Insert the following code to your form:

Private Sub Form_Load()
'Replace '800,600' with the resolution you want to switch to.
'You can change the color pallete to 32 - Bit by changing the '16' below with '32'

ChangeScreenSettings 800, 600, 16 - Bit
End Sub

Public Sub ChangeScreenSettings(lWidth As Integer, _
lHeight As Integer, lColors As Integer)
Dim tDevMode As DEVMODE, lTemp As Long, lIndex As Long
lIndex = 0
Do
lTemp = EnumDisplaySettings(0&, lIndex, tDevMode)
If lTemp = 0 Then Exit Do
lIndex = lIndex + 1
With tDevMode
If .dmPelsWidth = lWidth And .dmPelsHeight = lHeight _
And .dmBitsPerPel = lColors Then
lTemp = ChangeDisplaySettings(tDevMode, CDS_UPDATEREGISTRY)
Exit Do
End If
End With
Loop
Select Case lTemp
Case DISP_CHANGE_SUCCESSFUL
MsgBox "The display settings changed successfully", _
vbInformation
Case DISP_CHANGE_RESTART
MsgBox "The computer must be restarted in order for the graphics mode to work", vbQuestion
Case DISP_CHANGE_FAILED
MsgBox "The display driver failed the specified graphics mode", vbCritical
Case DISP_CHANGE_BADMODE
MsgBox "The graphics mode is not supported", vbCritical
Case DISP_CHANGE_NOTUPDATED
MsgBox "Unable to write settings to the registry", vbCritical
Case DISP_CHANGE_BADFLAGS
MsgBox "You Passed invalid data", vbCritical
End Select
End Sub

Go Back