Solved

Changing Screen Resolution/Frequency

Posted on 2002-04-29
9
320 Views
Last Modified: 2008-02-01
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
Comment
Question by:LeeOgley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

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

Cheers
0
 

Author Comment

by:LeeOgley
ID: 6980033
Increasing points to 200 as really need help on this.
0
 
LVL 1

Accepted Solution

by:
ProgramIT earned 200 total points
ID: 6985145
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 1

Expert Comment

by:ProgramIT
ID: 6985153
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 6987202
listening
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7002475
learning...
0
 
LVL 2

Expert Comment

by:nahumd
ID: 7008434
studying...
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7034353
To ProgramIt,

I try your code but doesn't work for Windows XP ?->
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7078687
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 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