This is from the MSDN library 6.0:
"<i>In a Microsoft Visual Basic® version 4.0 application, you can use the Windows application programming interface (API) EnumDisplaySettings and ChangeDisplaySettings functions to change the screen resolution while your program is running.
The EnumDisplaySettings function allows you to retrieve information about your display's graphics modes. This information is then stored in a DEVMODE structure.
After you have interrogated the computer system with the EnumDisplaySettings function, you use the ChangeDisplaySettings function to tell the operating system to use a different screen resolution.
The ChangeDisplaySettings function lets you set the screen resolution to a different graphics mode. The DEVMODE structure holds the graphics mode information to which you want to change.
In the example program below, you first retrieve the current screen resolution information by calling the EnumDisplaySettings function. The DEVMODE structure contains the graphics modes information for the display type. Next, you modify the dmPelsWidth and dmPelsHeight fields in the DEVMODE structure to reflect the new screen resolution you want to set. Finally, you call the ChangeDisplaySettings function to tell the operating system to set the new screen resolution as the default resolution</i>."
And here is some example code:
First, you need to declare the functions, and declare some constants and types:
<pre>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
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
Dim DevM As DEVMODE</pre>
Then, you retrieve the current display settings:
<pre> Dim a As Boolean
i = 0
a = EnumDisplaySettings(0&, i&, DevM)
i = i + 1
Loop Until (a = False)</pre>
And then you change the resolution:
<pre> Dim b&
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 1280
DevM.dmPelsHeight = 1024
b = ChangeDisplaySettings(DevM, 0)</pre>
Some additional code could be added to check the results in case you set an unsupported resolution.
Also, remember that changing the screen resolution could cause the desktop icons to change their position, which could annoy users.