Results 1 to 2 of 2

Thread: Setting screen resolution

  1. #1

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396

    Setting screen resolution

    Does anyone have code to set the screen resolution to: 1024x768?
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    From VBCode.com:
    VB Code:
    1. Public Const EWX_LOGOFF = 0
    2. Public Const EWX_SHUTDOWN = 1
    3. Public Const EWX_REBOOT = 2
    4. Public Const EWX_FORCE = 4
    5. Public Const CCDEVICENAME = 32
    6. Public Const CCFORMNAME = 32
    7. Public Const DM_BITSPERPEL = &H40000
    8. Public Const DM_PELSWIDTH = &H80000
    9. Public Const DM_PELSHEIGHT = &H100000
    10. Public Const CDS_UPDATEREGISTRY = &H1
    11. Public Const CDS_TEST = &H4
    12. Public Const DISP_CHANGE_SUCCESSFUL = 0
    13. Public Const DISP_CHANGE_RESTART = 1
    14.  
    15. Type typDevMODE
    16.     dmDeviceName       As String * CCDEVICENAME
    17.     dmSpecVersion      As Integer
    18.     dmDriverVersion    As Integer
    19.     dmSize             As Integer
    20.     dmDriverExtra      As Integer
    21.     dmFields           As Long
    22.     dmOrientation      As Integer
    23.     dmPaperSize        As Integer
    24.     dmPaperLength      As Integer
    25.     dmPaperWidth       As Integer
    26.     dmScale            As Integer
    27.     dmCopies           As Integer
    28.     dmDefaultSource    As Integer
    29.     dmPrintQuality     As Integer
    30.     dmColor            As Integer
    31.     dmDuplex           As Integer
    32.     dmYResolution      As Integer
    33.     dmTTOption         As Integer
    34.     dmCollate          As Integer
    35.     dmFormName         As String * CCFORMNAME
    36.     dmUnusedPadding    As Integer
    37.     dmBitsPerPel       As Integer
    38.     dmPelsWidth        As Long
    39.     dmPelsHeight       As Long
    40.     dmDisplayFlags     As Long
    41.     dmDisplayFrequency As Long
    42. End Type
    43.  
    44. Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lptypDevMode As Any) As Boolean
    45. Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lptypDevMode As Any, ByVal dwFlags As Long) As Long
    46. Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    47.  
    48. Dim typDevM As typDevMODE
    49. Dim lngResult As Long
    50. Dim intAns    As Integer
    51.  
    52. ' Retrieve info about the current graphics mode
    53. ' on the current display device.
    54. lngResult = EnumDisplaySettings(0, 0, typDevM)
    55.  
    56. ' Set the new resolution. Don't change the color
    57. ' depth so a restart is not necessary.
    58. With typDevM
    59.     .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
    60.     .dmPelsWidth = 1024
    61.     .dmPelsHeight = 768
    62. End With
    63.  
    64. ' Change the display settings to the specified graphics mode.
    65. lngResult = ChangeDisplaySettings(typDevM, CDS_TEST)
    66. Select Case lngResult
    67.     Case DISP_CHANGE_RESTART
    68.         intAns = MsgBox("You must restart your computer to apply these changes." & _
    69.             vbCrLf & vbCrLf & "Do you want to restart now?", _
    70.             vbYesNo + vbSystemModal, "Screen Resolution")
    71.         If intAns = vbYes Then Call ExitWindowsEx(EWX_REBOOT, 0)
    72.     Case DISP_CHANGE_SUCCESSFUL
    73.         Call ChangeDisplaySettings(typDevM, CDS_UPDATEREGISTRY)
    74.         MsgBox "Screen resolution changed", vbInformation, "Resolution Changed"
    75.     Case Else
    76.         MsgBox "Mode not supported", vbSystemModal, "Error"
    77. End Select
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width