Link to home
Start Free TrialLog in
Avatar of LeeOgley
LeeOgley

asked on

Changing Screen Resolution/Frequency

Hi,

I am trying to write a small VB program that a user can just double click and the users screen resolution will toggle between 1400x1050 @ 60Hz and 1280x1024 @ 75Hz.  

The machine is a laptop, and the laptops is optimised by 1400x1050 display, where as when it is docked the user is using a LG LCD display which is optimised at 1280x1024, running at different resolutions provides poor results

The code below is what I am using.

----------------------------------------------------------
    Dim DevM As DEVMODE
    Dim lScreenHeight As Long


    'Get the info into DevM
    erg& = EnumDisplaySettings(0&, ENUM_CURRENT_SETTINGS, DevM)
   

    lScreenHeight = GetSystemMetrics(SM_CXSCREEN)
   
    If (lScreenHeight = 1280) Then
        DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY
        DevM.dmPelsWidth = 1024                         ' ScreenWidth
        DevM.dmPelsHeight = 768                         ' ScreenHeight
        DevM.dmDisplayFrequency = 70                    ' Frequency
    Else
        DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY
        DevM.dmPelsWidth = 1280                         ' ScreenWidth
        DevM.dmPelsHeight = 1024                        ' ScreenHeight
        DevM.dmDisplayFrequency = 60                    ' Frequency
    End If

erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
----------------------------------------------------------

The code works but does not seem to retreive or set the display frequency correctly.  

Any advice/comments would be appreciated

Lee.
Avatar of LeeOgley
LeeOgley

ASKER

By the way, I'm writing/testing the software under Windows NT4, but the actual software will be running on Windows 2000

Cheers
Increasing points to 200 as really need help on this.
ASKER CERTIFIED SOLUTION
Avatar of ProgramIT
ProgramIT

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
By the way a simple sub could be:

Private Sub CheckRes()
    Dim TWIPX as long
    Dim TWIPY as long
    TWIPX = Screen.TwipsPerPixelX
    TWIPY = Screen.TwipsPerPixelY
    If Screen.Width \ TWIPX > 1280 Then   'Screen Res Higher than 1280 wide
        Call ChangeRes(1280, 1024, 75)
    Else    'Switch to 1400 mode
        Call ChangeRes(1400, 1050, 60)
    End If
End Sub

This would switch between the 2 modes as you requested.
Avatar of Mike McCracken
listening
learning...
studying...
To ProgramIt,

I try your code but doesn't work for Windows XP ?->
Greetings.

This question has been locked with a Proposed Answer, and remains open today.

If the Proposed Answer did not serve your needs, please reject it and comment with an update.  If the Proposed Answer helped you, please accept it to grade and close this question.  If you need help splitting points between multiple experts, please comment here with details so we can help you.

EXPERTS ->  Please guide me here in terms of closing recommendations if the Asker does not respond in 4 days.

Thanks to all,
Moondancer - EE Moderator