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

x
?
Solved

Detect Maximum Available Video Resolution

Posted on 2000-04-13
15
Medium Priority
?
456 Views
Last Modified: 2008-02-01
I need to know how I can get the maximum available video resolution for the currently selected display device.

Ex. I am using 800x600 resolution, but I want to switch to 1024x768. I need to know if the video adapter will support it before I try to switch.

Anyone know the API call or routine to do this?
0
Comment
Question by:orbitaltech
[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
  • 5
  • 3
  • 3
  • +2
15 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2712742
go to
http://www.matthart.com/vbhelp/vbmain.htm#CHANGEREZ
"How to change the video resolution in Windows 95 via code"
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 2712745
Here is how you can list supported modes:
Add a command button and a listbox to a form and copy this code:
Option Explicit

Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32

Private Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    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 * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type

Private Const DM_BITSPERPEL = &H40000
Private Const DM_PELSWIDTH = &H80000
Private Const DM_PELSHEIGHT = &H100000
Private Const DM_DISPLAYFLAGS = &H200000
Private Const DM_DISPLAYFREQUENCY = &H400000

Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpInitData As DEVMODE, ByVal dwFlags As Long) As Long
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (lpszDeviceName As Any, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

Private Const BITSPIXEL = 12

' Flags for ChangeDisplaySettings
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_TEST = &H2
Private Const CDS_FULLSCREEN = &H4
Private Const CDS_GLOBAL = &H8
Private Const CDS_SET_PRIMARY = &H10
Private Const CDS_RESET = &H40000000
Private Const CDS_SETRECT = &H20000000
Private Const CDS_NORESET = &H10000000

' Return values for ChangeDisplaySettings
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_RESTART = 1
Private Const DISP_CHANGE_FAILED = -1
Private Const DISP_CHANGE_BADMODE = -2
Private Const DISP_CHANGE_NOTUPDATED = -3
Private Const DISP_CHANGE_BADFLAGS = -4
Private Const DISP_CHANGE_BADPARAM = -5

Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4

Private D() As DEVMODE
Private lNumModes As Long

Private Sub Command1_Click()
Dim l As Long
Dim Flags As Long
Dim x As Long

    x = List1.ListIndex
    D(x).dmFields = DM_BITSPERPEL Or DM_PELSWIDTH Or DM_PELSHEIGHT
    Flags = CDS_UPDATEREGISTRY
    l = ChangeDisplaySettings(D(x), Flags)
    Select Case l
        Case DISP_CHANGE_RESTART
            l = MsgBox("This change will not take effect until you reboot the system. Reboot now?", vbYesNo)
            If l = vbYes Then
                Flags = 0
                l = ExitWindowsEx(EWX_REBOOT, Flags)
            End If
        Case DISP_CHANGE_SUCCESSFUL
        Case Else
            MsgBox "Error changing resolution! Returned: " & l
    End Select
End Sub

Private Sub Form_Load()
Dim l As Long
Dim lMaxModes As Long
Dim lBits As Long
Dim lWidth As Long
Dim lHeight As Long

    lBits = GetDeviceCaps(hdc, BITSPIXEL)
    lWidth = Screen.Width \ Screen.TwipsPerPixelX
    lHeight = Screen.Height \ Screen.TwipsPerPixelY
    lMaxModes = 8
    ReDim D(0 To lMaxModes) As DEVMODE
    lNumModes = 0
    l = EnumDisplaySettings(ByVal 0, lNumModes, D(lNumModes))
    Do While l
        List1.AddItem D(lNumModes).dmPelsWidth & "x" & D(lNumModes).dmPelsHeight & "x" & D(lNumModes).dmBitsPerPel
        If lBits = D(lNumModes).dmBitsPerPel And _
            lWidth = D(lNumModes).dmPelsWidth And _
            lHeight = D(lNumModes).dmPelsHeight Then
            List1.ListIndex = List1.NewIndex
        End If
        lNumModes = lNumModes + 1
        If lNumModes > lMaxModes Then
            lMaxModes = lMaxModes + 8
            ReDim Preserve D(0 To lMaxModes) As DEVMODE
        End If
        l = EnumDisplaySettings(ByVal 0, lNumModes, D(lNumModes))
    Loop
    lNumModes = lNumModes - 1
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2712746
See:

"Changing the screen resolution"
http://vb-world.net/tips/tip67.html
0
Independent Software Vendors: 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!

 
LVL 9

Expert Comment

by:Ruchi
ID: 2712753
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2712767
And Also:

"Changing the Display Resolution from Visual Basic"
http://www.mvps.org/vbnet/code/enums/enumdisplaychange.htm
0
 
LVL 2

Author Comment

by:orbitaltech
ID: 2712775
Mabye I should be more clear....

I already know how to change the resolution.

I need to know how to detect the maximum available resloution available for the display adapter.

The EnumDisplaySettings is probably what I want to do, but I can't figure out how to loop through the display modes using it.

What I need is some code or some help with actually retreiving the max resolution using the API

ANy other suggestions?
0
 
LVL 2

Author Comment

by:orbitaltech
ID: 2712779
emoreau,

Give me a sec to try your proposal.. Give me about 1 hour

Thanx
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2712792
The correct address is
http://blackbeltvb.com/index.htm?free/changrez.htm 
"Utilizes API calls to enumerate possible video settings. Switches the system to the selected setting and reboots if necessary. pre-selection. Uses the following API functions:"

http://www5.50megs.com/andreavb/tip090002.html
"Get the current Video settings: Colors, Resolution and Pixels per Inch... "
0
 
LVL 20

Expert Comment

by:hes
ID: 2712812
emoreau's suggestion does return all the available resolutions
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2712975
emoreau's suggestion returns available resolutions for your hardware settings!
0
 
LVL 20

Expert Comment

by:hes
ID: 2713020
:) That's what I ment emoreau, should have typed it clearer < smile >
0
 
LVL 2

Author Comment

by:orbitaltech
ID: 2713038
emoreau,

Give me a sec to try your proposal.. Give me about 1 hour

Thanx
0
 
LVL 2

Author Comment

by:orbitaltech
ID: 2713117
Thank you.

 I only needed to enumerate through the currently select video adapter and what you gave me worked.
0
 
LVL 2

Author Comment

by:orbitaltech
ID: 2713464
Question?

After i change the resolution fo the display adapter, I noticed a few things (at least on NT 4.0 this happens)

#1) If you right-click on the desktop and select properties and select settings, the resolution slider is still set to the old resolution. (Mabye a reboot fixes this?)

#2) if I use
screen.width / screen.twipsperpixelX
screen.height / screen.twipsperpixelY

the return values are both the same (in my case 768)

Anybody know why this happens? Is this a confirmed bug in NT 4.0?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2713539
Try this after changing resolution:

Private Declare Function SystemParametersInfo _
                Lib "user32" _
                Alias "SystemParametersInfoA" _
                (ByVal uAction As Long, _
                 ByVal uParam As Long, _
                 lpvParam As Any, _
                 ByVal fuWinIni As Long _
                ) As Long

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
   
Private Const SPI_GETWORKAREA = 48

Private Sub MDIForm_Load()
Dim WA As RECT

'Récupère les dimensions de l'application
lngReturn = SystemParametersInfo(SPI_GETWORKAREA, 0&, WA, 0&)
WA.Left = WA.Left * Screen.TwipsPerPixelX
WA.Right = WA.Right * Screen.TwipsPerPixelX
WA.Top = WA.Top * Screen.TwipsPerPixelY
WA.Bottom = WA.Bottom * Screen.TwipsPerPixelY
End Sub
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 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