Display Resolution - Hertz Problem (1 Viewer)

razaqad

Raza
Local time
Today, 13:48
Joined
Mar 12, 2006
Messages
83
Im using the following code to change the display resolution:
Code:
Option Compare Database
Option Explicit

'ghudson 08/30/2002
'I am trying to reduce the repetitive code but it is not working.
 
'http://www.vbcode.com/asp/showsn.asp?theID=6142

    '*** These two lines to be added if OS is Windows 2000 ***
    '*** in DEVMODE declaration ***

    ' dmPanningWidth As Long
    ' dmPanningHeight As Long

Public Type DEVMODE
    dmDeviceName As String * 32
    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 * 32
    dmUnusedPadding As Integer
    dmBitsPerPixel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    dmICMMethod As Long
    dmICMIntent As Long
    dmMediaType As Long
    dmDitherType As Long
    dmReserved1 As Long
    dmReserved2 As Long
    dmPanningWidth As Long
    dmPanningHeight As Long

End Type

Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long
Public Const ENUM_CURRENT_SETTINGS = -1
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H2
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1

Public Function ChangeResolution(vWidth As Variant, vHeight As Variant)
On Error GoTo Err_ChangeResolution

    Dim dm As DEVMODE
    Dim RetVal As Long
    
    dm.dmSize = Len(dm)
    RetVal = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)

    dm.dmPelsWidth = vWidth  ' Width should be numeric (e.g. 1024 or 800 or 640)
    dm.dmPelsHeight = vHeight ' Height should be numeric (e.g. 768 or 600 or 480)

    RetVal = ChangeDisplaySettings(dm, CDS_TEST)
    If RetVal <> DISP_CHANGE_SUCCESSFUL Then
        Debug.Print "Cannot change to that resolution!"
    Else
        RetVal = ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY)
        Select Case RetVal
        Case DISP_CHANGE_SUCCESSFUL
            Debug.Print "Resolution successfully changed!"
        Case DISP_CHANGE_RESTART
            Debug.Print "A reboot is necessary before the changes will take effect."
        Case Else
            Debug.Print "Unable to change resolution!"
        End Select
    End If

Exit_ChangeResolution:
    Exit Function

Err_ChangeResolution:
    MsgBox Err.Number, Err.Description
    Resume Exit_ChangeResolution

End Function

This code works perfctly on my pc but on my friend's pc i'm having problem.

The problem is that , my friend's pc does not support higher refresh rate on 1024x 768 resolution.

So when the previous resolution is set to 800x600 @ 60 Hertz this code works fine. But if the resolution is 800x600@ 85 Hertz this code does not work.

Is there a way that the code retry to change the resoluton with lower refresh rate like 75 Htz if this fails then try 70 ..... and 60Htz and if all tries fail then give up else set the resolution at refresh rate at highest possible rate.
 

ghudson

Registered User.
Local time
Today, 05:48
Joined
Jun 8, 2002
Messages
6,194
Where did you did that dinosaur up from?

You would be wise not to mess with the users computer [display] settings. There is a reason the users have their computers setup the way that they do for that is how they want it.
 

razaqad

Raza
Local time
Today, 13:48
Joined
Mar 12, 2006
Messages
83
I totally understant and i have read your comments on the thread from where i got that code.

But still there are some situations you need to play with user's computer settings.

Ghudson you have created/modified this peice of code. can you help me in this matter.
 

razaqad

Raza
Local time
Today, 13:48
Joined
Mar 12, 2006
Messages
83
And i never change these settings without asking user's permission.
A msg box is diplayed asking the user that he wants to change the settings or not ....
 

ghudson

Registered User.
Local time
Today, 05:48
Joined
Jun 8, 2002
Messages
6,194
razaqad said:
But still there are some situations you need to play with user's computer settings.
I disagree!

razaqad said:
Ghudson you have created/modified this peice of code. can you help me in this matter.
Not a clue. I played with that code years ago when I thought I had a need to use it [I have never put it into production on any of my apps]. The code is only allowing you to alter the resolution, not the refresh rate. If you can not trap for a specific error number then I advise you to leave this one alone. If you must, try searching the true Visual Basic code sites for that is where I found that code [years ago]. Good luck!
 

Users who are viewing this thread

Top Bottom