Results 1 to 5 of 5

Thread: change resolution to 1024x768

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    change resolution to 1024x768

    using vb6, how can i change my screen resolution to 1024x768 if the screen resolution is 800x600. and when u unload the program. it automatically returns to 800x600

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: change resolution to 1024x768

    See this

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: change resolution to 1024x768

    This will get your aim,
    VB Code:
    1. Option Explicit
    2. Const WM_DISPLAYCHANGE = &H7E
    3. Const HWND_BROADCAST = &HFFFF&
    4. Const EWX_LOGOFF = 0
    5. Const EWX_SHUTDOWN = 1
    6. Const EWX_REBOOT = 2
    7. Const EWX_FORCE = 4
    8. Const CCDEVICENAME = 32
    9. Const CCFORMNAME = 32
    10. Const DM_BITSPERPEL = &H40000
    11. Const DM_PELSWIDTH = &H80000
    12. Const DM_PELSHEIGHT = &H100000
    13. Const CDS_UPDATEREGISTRY = &H1
    14. Const CDS_TEST = &H4
    15. Const DISP_CHANGE_SUCCESSFUL = 0
    16. Const DISP_CHANGE_RESTART = 1
    17. Const BITSPIXEL = 12
    18. Private Type DEVMODE
    19.     dmDeviceName As String * CCDEVICENAME
    20.     dmSpecVersion As Integer
    21.     dmDriverVersion As Integer
    22.     dmSize As Integer
    23.     dmDriverExtra As Integer
    24.     dmFields As Long
    25.     dmOrientation As Integer
    26.     dmPaperSize As Integer
    27.     dmPaperLength As Integer
    28.     dmPaperWidth As Integer
    29.     dmScale As Integer
    30.     dmCopies As Integer
    31.     dmDefaultSource As Integer
    32.     dmPrintQuality As Integer
    33.     dmColor As Integer
    34.     dmDuplex As Integer
    35.     dmYResolution As Integer
    36.     dmTTOption As Integer
    37.     dmCollate As Integer
    38.     dmFormName As String * CCFORMNAME
    39.     dmUnusedPadding As Integer
    40.     dmBitsPerPel As Integer
    41.     dmPelsWidth As Long
    42.     dmPelsHeight As Long
    43.     dmDisplayFlags As Long
    44.     dmDisplayFrequency As Long
    45. End Type
    46. Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
    47. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
    48. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    49. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    50. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
    51. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    52. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    53. Dim OldX As Long, OldY As Long, nDC As Long
    54. Sub ChangeRes(X As Long, Y As Long, Bits As Long)
    55.     Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
    56.     'Get the info into DevM
    57.     erg = EnumDisplaySettings(0&, 0&, DevM)
    58.     'This is what we're going to change
    59.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    60.     DevM.dmPelsWidth = X 'ScreenWidth
    61.     DevM.dmPelsHeight = Y 'ScreenHeight
    62.     DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
    63.     'Now change the display and check if possible
    64.     erg = ChangeDisplaySettings(DevM, CDS_TEST)
    65.     'Check if succesfull
    66.     Select Case erg&
    67.         Case DISP_CHANGE_RESTART
    68.             an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
    69.             If an = vbYes Then
    70.                 erg& = ExitWindowsEx(EWX_REBOOT, 0&)
    71.             End If
    72.         Case DISP_CHANGE_SUCCESSFUL
    73.             erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
    74.             ScInfo = Y * 2 ^ 16 + X
    75.             'Notify all the windows of the screen resolution change
    76.             SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
    77.             MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
    78.         Case Else
    79.             MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
    80.     End Select
    81. End Sub
    82. Private Sub Form_Load()
    83.     Dim nDC As Long
    84.     'retrieve the screen's resolution
    85.     OldX = Screen.Width / Screen.TwipsPerPixelX
    86.     OldY = Screen.Height / Screen.TwipsPerPixelY
    87.     'Create a device context, compatible with the screen
    88.     nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
    89.     'Change the screen's resolution
    90.    
    91.     ChangeRes 1024, 728, GetDeviceCaps(nDC, BITSPIXEL)
    92. End Sub
    93. Private Sub Form_Unload(Cancel As Integer)
    94.     'restore the screen resolution
    95.     ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
    96.     'delete our device context
    97.     DeleteDC nDC
    98. End Sub

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: change resolution to 1024x768


  5. #5
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: change resolution to 1024x768

    Quote Originally Posted by rory
    I think that the rory code is very fine, this is perfectly giving the best result

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