.exe file to change screen resolution settings

Can VB Express Edition be used to develop an .exe file that, when run, will change screen resolution from one setting to another (e.g. 1024x768 to 1280X720)

If so, what template would/should be used and where might I find more information on how to do it

Any feedback would be appreciated.

Thank you




Answer this question

.exe file to change screen resolution settings

  • quan

    The code I provided works in Visual Basic, not Vicual C++ (this is a VB forum). To make it work, open VB, make a new EXE project, then in the code window for Form1, replace the default text with the code I provided. Then, in the solution manager, open 'My Project', click references, then click add. Then click the COM tab. Then select Microsoft DirectX7 for Visual Basic Type Library or something similar.

    P.S. Thanks, I 'borrowed' the joke off a friend :P

    P.P.S. The depth variable represents the colour depth of the screen, in bits. 8-bit means 256 colour mode, 16-bit means high colour mode, and 24 and 32 bit represent true colour and ultra true colour, respectively.

    P.P.P.S. Sorry I took so long to reply. I've been quite caught up doing stuff recently.


  • Asmodyne

    For the slightly thick people among us who don't know much C#...

    Do I just create a form and insert this into it or do I create a class file If so, how do I link the class file to the main form of the program

    Thanks,

    Timothy

     

     If you dont try - you'll never know.

     P.s. I like the binary quote-thingy-joke-pun robinjam :)

    P.p.s. What does the "depth=16" signify


  • Dali Hammadi

    It's a whole lot easier to use DirectDraw, and it automatically restores to the display mode that the application was used in when the application ends, or if the screen can't cope with the resolution. This is my opinion, but try using this code:

     

    Imports DxVBLib

    Public Class frmMain

      Dim dx As New DirectX7

      Dim dd As DirectDraw7

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Show()

        dd = dx.DirectDrawCreate("")

        dim Height as Integer

        dim Width as Integer

        dim Depth as Integer

        Height=600 ' Change this to the correct number

        Width=800 ' Change this to the correct number

        Depth=16 ' Change this to the correct number

        dd.SetDisplayMode(Height, Width, Depth, 0, CONST_DDSDMFLAGS.DDSDM_DEFAULT)

      End Sub

    End Class

     

    REMEMBER to add a COM reference to DirectX7 for Visual Basic Type Library before you try this.

     

    EDIT:
        dd.SetDisplayMode(Height, Width, Depth, 0, CONST_DDSDMFLAGS.DDSDM_DEFAULT)
    is wrong. It should be:
        dd.SetDisplayMode(Width, Height, Depth, 0, CONST_DDSDMFLAGS.DDSDM_DEFAULT)



  • cheetoz

    The only way i'm aware of is using microsoft directdraw's SetDisplayMode(width,height,bpp,0,0) function.

  • Nitin Mittal

    As a side note, remember that just because you can, doesn't necessarily mean you should.

    If this is a 'standard' windows application, then you probably shouldn't - people don't like programs messing with their stuff. If it's a game type application, designed to run full screen with fast graphics, then it's OK - it's pretty much expected so the end user can maximize the performance. You still have to ask (the user), though.

    If it's for your own use, then have at it. Remember also that some monitors can't change to some resolutions at certain refresh rates - if your program changes to a resolution that can't be displayed by the monitor, how will the user get it back

     



  • Luís Oliveira

    Here is the way i do it, works in 2005

    [code]

    Private Declare Auto Function EnumDisplaySettings Lib "user32.dll" ( _

    <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszDeviceName As String, _

    ByVal iModeNum As Int32, _

    ByRef lpDevMode As DEVMODE _

    ) As Boolean

    Private Declare Auto Function ChangeDisplaySettings Lib "user32.dll" ( _

    ByRef lpDevMode As DEVMODE, _

    ByVal dwFlags As Int32 _

    ) As Int32

    Private Const DM_BITSPERPEL As Int32 = &H40000

    Private Const DM_PELSWIDTH As Int32 = &H80000

    Private Const DM_PELSHEIGHT As Int32 = &H100000

    Private Const DISP_CHANGE_SUCCESSFUL As Int32 = 0

    <StructLayout(LayoutKind.Sequential)> _

    Private Structure POINTL

    Public x As Int32

    Public y As Int32

    End Structure

    <StructLayout(LayoutKind.Explicit)> _

    Private Structure DEVMODE_union1

    ' struct {

    <FieldOffset(0)> Public dmOrientation As Int16

    <FieldOffset(2)> Public dmPaperSize As Int16

    <FieldOffset(4)> Public dmPaperLength As Int16

    <FieldOffset(6)> Public dmPaperWidth As Int16

    ' }

    <FieldOffset(0)> Public dmPosition As POINTL

    End Structure

    <StructLayout(LayoutKind.Explicit)> _

    Private Structure DEVMODE_union2

    <FieldOffset(0)> Public dmDisplayFlags As Int32

    <FieldOffset(0)> Public dmNup As Int32

    End Structure

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

    Private Structure DEVMODE

    Private Const CCDEVICENAME As Int32 = 32

    Private Const CCFORMNAME As Int32 = 32

    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _

    Public dmDeviceName As String

    Public dmSpecVersion As Int16

    Public dmDriverVersion As Int16

    Public dmSize As Int16

    Public dmDriverExtra As Int16

    Public dmFields As Int32

    Public u1 As DEVMODE_union1

    Public dmScale As Int16

    Public dmCopies As Int16

    Public dmDefaultSource As Int16

    Public dmPrintQuality As Int16

    Public dmColor As Int16

    Public dmDuplex As Int16

    Public dmYResolution As Int16

    Public dmTTOption As Int16

    Public dmCollate As Int16

    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _

    Public dmFormName As String

    Public dmUnusedPadding As Int16

    Public dmBitsPerPel As Int16

    Public dmPelsWidth As Int32

    Public dmPelsHeight As Int32

    Public u2 As DEVMODE_union2

    Public dmDisplayFrequency As Int32

    Public dmICMMethod As Int32

    Public dmICMIntent As Int32

    Public dmMediaType As Int32

    Public dmDitherType As Int32

    Public dmReserved1 As Int32

    Public dmReserved2 As Int32

    Public dmPanningWidth As Int32

    Public dmPanningHeight As Int32

    End Structure

    Public Function SetResolution( _

    ByVal Width As Int32, _

    ByVal Height As Int32, _

    ByVal BitsPerPixel As Int16 _

    ) As Boolean

    Dim dm As DEVMODE

    If Not EnumDisplaySettings(Nothing, 0, dm) Then

    Return False

    Else

    With dm

    .dmFields = _

    DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL

    .dmPelsWidth = Width

    .dmPelsHeight = Height

    .dmBitsPerPel = BitsPerPixel

    End With

    Return (ChangeDisplaySettings(dm, 0) = DISP_CHANGE_SUCCESSFUL)

    End If

    End Function

    [/code]

    To use this code (on formload or a buton click)

    [code]

    Debug.Assert(SetResolution(1600, 1200, 32)

    [/code]

    If you don't want the bps 2 change (great for portable app) then do this code on form load before u set res.

    Dim bps As Short = System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel

    then you use this 2 set res instead

    Debug.Assert(SetResolution(1600, 1200, bps)

    Hope it helps,

    Robert Baker

     



  • Tiago Fusco

    Does this answer your question, Tim

  • .exe file to change screen resolution settings