Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 28,440 times

Related Categories

Change Resolution

Add the code below to a module. You can then call ChangeRes to change the resolution, specifying the width and height. For example, ChangeRes 800,600

'Changes resolution on the fly, without rebooting
'Call with:
'Call ChangeRes(800,600)
'or Call ChangeRes(640,480) for example
' if resolution is not possible, a dialog is displayed
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long

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

Private 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
Dim DevM As DEVMODE

Sub ChangeRes(iWidth As Single, iHeight As Single)
    Dim a As Boolean
    Dim i As Integer
    i = 0
    Do
        a = EnumDisplaySettings(0&, i, DevM)
        i = i + 1
    Loop Until (a = False)

    Dim b&
    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT

    DevM.dmPelsWidth = iWidth
    DevM.dmPelsHeight = iHeight

    ChangeDisplaySettings DevM, 0
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • changedisplaysettings problem

    Posted by maheeru on 07 Aug 2005

    Though code gives partial success it has a catch. I want my application to be arranged as normal in the desktop. thats ok. But taskbar disappears I suppose it goes down. How to change the above cod...

  • vb.net

    Posted by ffranko99 on 07 May 2003

    I am using vb.net, is there a updated version for it.

    thanks

  • Colours

    Posted by HyperHacker on 27 Apr 2003

    How would we change colour depth?

  • Posted by iganesh77 on 03 Apr 2003

    hi,
    use the following so taskbar will set in the same position.....

    'Declare the following
    Private Const CDS_UPDATEREGISTRY = &H1

    'change the following in "ChangeRes"
    ChangeDisplaySettings De...

  • Updated Version?

    Posted by Cillroy on 17 Dec 2002

    Any chance of finding an equivalent for VB.Net and rotating the screen? ie Tablet XP