Link to home
Start Free TrialLog in
Avatar of ashraf_t
ashraf_t

asked on

Change Screen Resolution and Refresh rate

Hi everyone , what is the simplest code for reetrive and change the screen resolution and screen refresh rate , Thanx a lot
Avatar of Matti
Matti
Flag of Finland image

Hi!

Try this.
I'm not sure do the frequency change work in every case, also there might be improper values to the display so be careful whit that.

Matti
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
    End Type
 
Sub ChangeRes(iWidth As Single, iHeight As Single, frequency As Long)
    Dim DevM As DEVMODE
    Dim a As Boolean
    Dim i&
    i = 0
    Do
        a = EnumDisplaySettings(0&, i&, DevM)
        i = i + 1
    Loop Until (a = False)
    Dim b&
    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
    DevM.dmPelsWidth = iWidth
    DevM.dmPelsHeight = iHeight
    DevM.dmDisplayFrequency = frequency
    b = ChangeDisplaySettings(DevM, 0)
End Sub
 'make the cal from this button
Private Sub Command1_Click()
Call ChangeRes(1280, 1024, 70)
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mortaza Doulaty
Mortaza Doulaty
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial