How to change System Resolution
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 'System & API - How to change System Resolution Option Explicit 'The program will prompt to you if the computer must be restarted to apply changes. 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 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 |