Results 1 to 12 of 12

Thread: [RESOLVED] Screen Res

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Resolved [RESOLVED] Screen Res

    How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?

    if possible can i change it back to what it was before the program was opened when it is exited?

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

    Thumbs up Re: Screen Res

    Quote Originally Posted by dannyg
    How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?

    if possible can i change it back to what it was before the program was opened when it is exited?
    Welcome on the forums
    Look at my sign resoulation free control

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Screen Res

    AllAPI has this example:

    http://www.allapi.net/apilist/Change...ettings.shtml#

    Click the "Change Resolution" link under Examples.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

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

    Re: Screen Res

    Form
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     ResizeDisplay True, 1024, 768
    5. End Sub
    6.  
    7. Private Sub Form_Unload(Cancel As Integer)
    8.     ResizeDisplay (False)
    9. End Sub

    Module
    VB Code:
    1. Option Explicit
    2.  
    3. Const WM_DISPLAYCHANGE = &H7E
    4. Const HWND_BROADCAST = &HFFFF&
    5. Const EWX_LOGOFF = 0
    6. Const EWX_SHUTDOWN = 1
    7. Const EWX_REBOOT = 2
    8. Const EWX_FORCE = 4
    9. Const CCDEVICENAME = 32
    10. Const CCFORMNAME = 32
    11. Const DM_BITSPERPEL = &H40000
    12. Const DM_PELSWIDTH = &H80000
    13. Const DM_PELSHEIGHT = &H100000
    14. Const CDS_UPDATEREGISTRY = &H1
    15. Const CDS_TEST = &H4
    16. Const DISP_CHANGE_SUCCESSFUL = 0
    17. Const DISP_CHANGE_RESTART = 1
    18. Const BITSPIXEL = 12
    19.  
    20. Private Type DEVMODE
    21.     dmDeviceName As String * CCDEVICENAME
    22.     dmSpecVersion As Integer
    23.     dmDriverVersion As Integer
    24.     dmSize As Integer
    25.     dmDriverExtra As Integer
    26.     dmFields As Long
    27.     dmOrientation As Integer
    28.     dmPaperSize As Integer
    29.     dmPaperLength As Integer
    30.     dmPaperWidth As Integer
    31.     dmScale As Integer
    32.     dmCopies As Integer
    33.     dmDefaultSource As Integer
    34.     dmPrintQuality As Integer
    35.     dmColor As Integer
    36.     dmDuplex As Integer
    37.     dmYResolution As Integer
    38.     dmTTOption As Integer
    39.     dmCollate As Integer
    40.     dmFormName As String * CCFORMNAME
    41.     dmUnusedPadding As Integer
    42.     dmBitsPerPel As Integer
    43.     dmPelsWidth As Long
    44.     dmPelsHeight As Long
    45.     dmDisplayFlags As Long
    46.     dmDisplayFrequency As Long
    47. End Type
    48.  
    49. Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
    50. (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
    51. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _
    52. (lpDevMode As Any, ByVal dwFlags As Long) As Long
    53. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    54. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    55. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, _
    56. ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
    57. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    58. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    59. ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    60.  
    61. Public OldX As Long
    62. Public OldY As Long
    63. Public nDC As Long
    64.  
    65. Private Sub ChangeResolution(x As Long, y As Long, Bits As Long)
    66.     Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
    67.     erg = EnumDisplaySettings(0&, 0&, DevM)
    68.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    69.     DevM.dmPelsWidth = x
    70.     DevM.dmPelsHeight = y
    71.     DevM.dmBitsPerPel = Bits
    72.     erg = ChangeDisplaySettings(DevM, CDS_TEST)
    73.     Select Case erg&
    74.         Case DISP_CHANGE_RESTART
    75.             an = MsgBox("You need to restart your computer for new settings to take effect.", vbYesNo + vbSystemModal, "Info")
    76.             If an = vbYes Then
    77.                 erg& = ExitWindowsEx(EWX_REBOOT, 0&)
    78.             End If
    79.         Case DISP_CHANGE_SUCCESSFUL
    80.             erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
    81.             ScInfo = y * 2 ^ 16 + x
    82.             SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
    83.             'MsgBox "Resolution has been changed...", vbOKOnly + vbExclamation, "Resolution Change"
    84.         Case Else
    85.             MsgBox "Display setting is not supported", vbOKOnly + vbCritical, "Error"
    86.     End Select
    87. End Sub
    88.  
    89. Public Sub ResizeDisplay(ByVal ENABLED As Boolean, Optional ByVal x As Long, Optional ByVal y As Long)
    90.     If ENABLED And Not IsMissing(x) And Not IsMissing(y) Then
    91.         If x And y > 0 Then
    92.             OldX = Screen.Width / Screen.TwipsPerPixelX
    93.             OldY = Screen.Height / Screen.TwipsPerPixelY
    94.             nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
    95.             ChangeResolution x, y, GetDeviceCaps(nDC, BITSPIXEL)
    96.         End If
    97.     Else
    98.         If OldX And OldY > 0 Then
    99.             ChangeResolution OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
    100.             DeleteDC nDC
    101.         End If
    102.     End If
    103. End Sub
    Last edited by rory; Oct 13th, 2006 at 06:05 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: Screen Res

    It says display setting not supported when form closes :\
    Last edited by dannyg; Oct 13th, 2006 at 06:01 AM.

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

    Re: Screen Res

    yeah sorry .. edited above code.

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

    Thumbs up Re: Screen Res

    Quote Originally Posted by dannyg
    It says display setting not supported when form closes :\
    Check the code again

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

    Re: Screen Res

    Quote Originally Posted by shakti5385
    Check the code again
    works .. i had an extra condition in the main sub i didnt need ..
    check now ..

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: Screen Res

    got it working now thnx

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

    Re: [RESOLVED] Screen Res

    no prob .. had the code laying around in an old form ..
    just made the new sub and put it in a module for easier use. .

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

    Thumbs up Re: [RESOLVED] Screen Res

    Quote Originally Posted by rory
    no prob .. had the code laying around in an old form ..
    just made the new sub and put it in a module for easier use. .
    good code by you boom

  12. #12
    Lively Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    86

    Cool Re: [RESOLVED] Screen Res

    Sorry to bump such and Old thread but its better then starting a new one.

    I using this code.. it "works" fine BUT after I do this:
    ResizeDisplay True, 1024, 768
    it looks the right size but it sets my Screen.Width to 11520 and my Screen.Height to 11520.

    These numbers shouldn't be the same, the width should be like 15360 or something.

    Could you tell me what i'm doing wrong or why its doing this?
    I copied the Code exactly.
    Please Help

    using VB6.0 on WinXP SP2.0

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