Solved

Changing Screen Resolution/Frequency

Posted on 2002-04-29
9
315 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
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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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

15 Experts available now in Live!

Get 1:1 Help Now