Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing Screen Resolution/Frequency

Posted on 2002-04-29
9
Medium Priority
?
327 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 101

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…
Suggested Courses

618 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