Change Screen Resolution and Refresh rate

Posted on 2007-11-17
Last Modified: 2012-05-05
Hi everyone , what is the simplest code for reetrive and change the screen resolution and screen refresh rate , Thanx a lot
Question by:ashraf_t
LVL 14

Expert Comment

ID: 20303924

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.

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


        a = EnumDisplaySettings(0&, i&, DevM)

        i = i + 1

    Loop Until (a = False)

    Dim b&


    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


Expert Comment

ID: 20303963
LVL 12

Accepted Solution

Mortaza Doulaty earned 100 total points
ID: 20306898

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now