Results 1 to 4 of 4

Thread: [RESOLVED] Forcing a screen resolution change?

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Resolved [RESOLVED] Forcing a screen resolution change?

    I want my app to be run in 1280x1024 resolution, just for clarity's sake... What would I need to change the screen's resolution?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Forcing a screen resolution change?

    hiya!

    In a module:
    VB Code:
    1. Public Const CCDEVICENAME = 32
    2. Public Const CCFORMNAME = 32
    3. Public Const DISP_CHANGE_SUCCESSFUL = 0
    4. Public Const DISP_CHANGE_RESTART = 1
    5. Public Const DISP_CHANGE_FAILED = -1
    6. Public Const DISP_CHANGE_BADMODE = -2
    7. Public Const DISP_CHANGE_NOTUPDATED = -3
    8. Public Const DISP_CHANGE_BADFLAGS = -4
    9. Public Const DISP_CHANGE_BADPARAM = -5
    10. Public Const CDS_UPDATEREGISTRY = &H1
    11. Public Const CDS_TEST = &H2
    12. Public Const DM_BITSPERPEL = &H40000
    13. Public Const DM_PELSWIDTH = &H80000
    14. Public Const DM_PELSHEIGHT = &H100000
    15. Public Type DEVMODE
    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. Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
    44. (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, _
    45. lpDevMode As Any) As Boolean
    46. Declare Function ChangeDisplaySettings Lib "user32" Alias _
    47. "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

    And on your form:

    VB Code:
    1. Private Sub Form_Load()
    2.  ChangeScreenSettings 1024, 768, 32 - Bit
    3. End Sub
    4.  
    5.  
    6. Public Sub ChangeScreenSettings(lWidth As Integer, _
    7. lHeight As Integer, lColors As Integer)
    8. Dim tDevMode As DEVMODE, lTemp As Long, lIndex As Long
    9. lIndex = 0
    10. Do
    11. lTemp = EnumDisplaySettings(0&, lIndex, tDevMode)
    12. If lTemp = 0 Then Exit Do
    13. lIndex = lIndex + 1
    14. With tDevMode
    15. If .dmPelsWidth = lWidth And .dmPelsHeight = lHeight _
    16. And .dmBitsPerPel = lColors Then
    17. lTemp = ChangeDisplaySettings(tDevMode, CDS_UPDATEREGISTRY)
    18. Exit Do
    19. End If
    20. End With
    21. Loop
    22. Select Case lTemp
    23. Case DISP_CHANGE_SUCCESSFUL
    24. MsgBox "The display settings changed successfully", _
    25. vbInformation
    26. Case DISP_CHANGE_RESTART
    27. MsgBox "The computer must be restarted in order for the graphics mode to work", vbQuestion
    28. Case DISP_CHANGE_FAILED
    29. MsgBox "The display driver failed the specified graphics mode", vbCritical
    30. Case DISP_CHANGE_BADMODE
    31. MsgBox "The graphics mode is not supported", vbCritical
    32. Case DISP_CHANGE_NOTUPDATED
    33. MsgBox "Unable to write settings to the registry", vbCritical
    34. Case DISP_CHANGE_BADFLAGS
    35. MsgBox "You Passed invalid data", vbCritical
    36. End Select
    37. End Sub

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Forcing a screen resolution change?

    dear god... now i'm almost sorry i asked...

    Thanks anyway!

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Forcing a screen resolution change?

    hehe well its functional
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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