• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

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.
0
LeeOgley
Asked:
LeeOgley
1 Solution
 
LeeOgleyAuthor Commented:
By the way, I'm writing/testing the software under Windows NT4, but the actual software will be running on Windows 2000

Cheers
0
 
LeeOgleyAuthor Commented:
Increasing points to 200 as really need help on this.
0
 
ProgramITCommented:
This is the routine I use for changinging display resolutions.  I normally don't use the dmDisplayFrequency setting but leave it at default. but by adding the DevM.dmDisplayFrequency = 75 or whateverthen it will adjust frequency as well.
By placing the code below in a module and then you can use:
Changeres 1400, 1050, 60


'Module code
Public Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long

Public Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean

Public Const CCFORMNAME = 32
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000

Public 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

Public Sub ChangeRes(iWidth As Single, iHeight As Single, Optional 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
    if Frequency > 0 then
        DevM.dmDisplayFrequency = Frequency
    End if
    DevM.dmPelsWidth = iWidth
    DevM.dmPelsHeight = iHeight

    b = ChangeDisplaySettings(DevM, 0)
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ProgramITCommented:
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.
0
 
mlmccCommented:
listening
0
 
Richie_SimonettiIT OperationsCommented:
learning...
0
 
nahumdCommented:
studying...
0
 
EDDYKTCommented:
To ProgramIt,

I try your code but doesn't work for Windows XP ?->
0
 
MoondancerCommented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now