Results 1 to 11 of 11

Thread: Scren res

  1. #1

    Thread Starter
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409

    Scren res

    can you change the screen resolution of the computer in runtime in vb6

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Try this...

    VB Code:
    1. Private Const WM_DISPLAYCHANGE = &H7E
    2. Private Const HWND_BROADCAST = &HFFFF&
    3. Private Const EWX_LOGOFF = 0
    4. Private Const EWX_SHUTDOWN = 1
    5. Private Const EWX_REBOOT = 2
    6. Private Const EWX_FORCE = 4
    7. Private Const CCDEVICENAME = 32
    8. Private Const CCFORMNAME = 32
    9. Private Const DM_BITSPERPEL = &H40000
    10. Private Const DM_PELSWIDTH = &H80000
    11. Private Const DM_PELSHEIGHT = &H100000
    12. Private Const CDS_UPDATEREGISTRY = &H1
    13. Private Const CDS_TEST = &H4
    14. Private Const DISP_CHANGE_SUCCESSFUL = 0
    15. Private Const DISP_CHANGE_RESTART = 1
    16. Private Const BITSPIXEL = 12
    17.  
    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.  
    47. Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
    48. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
    49. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    50. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    51. 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
    52. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    53. 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
    54.  
    55. Private OldX As Long
    56. Private OldY As Long
    57. Private nDC As Long
    58.  
    59.  
    60. Private Sub ChangeRes(X As Long, Y As Long, Bits As Long)
    61.     Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
    62.     'Get the info into DevM
    63.     erg = EnumDisplaySettings(0&, 0&, DevM)
    64.     'This is what we're going to change
    65.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    66.     DevM.dmPelsWidth = X 'ScreenWidth
    67.     DevM.dmPelsHeight = Y 'ScreenHeight
    68.     DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
    69.     'Now change the display and check if possible
    70.     erg = ChangeDisplaySettings(DevM, CDS_TEST)
    71.     'Check if succesfull
    72.     Select Case erg&
    73.         Case DISP_CHANGE_RESTART
    74.             an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
    75.             If an = vbYes Then
    76.                 erg& = ExitWindowsEx(EWX_REBOOT, 0&)
    77.             End If
    78.         Case DISP_CHANGE_SUCCESSFUL
    79.             erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
    80.             ScInfo = Y * 2 ^ 16 + X
    81.             'Notify all the windows of the screen resolution change
    82.             SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
    83.             MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
    84.         Case Else
    85.             MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
    86.     End Select
    87. End Sub
    88.  
    89. Private Sub Command1_Click()
    90. 'KPD-Team 1999
    91.     'URL: [url]http://www.allapi.net/[/url]
    92.     'E-Mail: [email][email protected][/email]
    93.     Dim nDC As Long
    94.     'retrieve the screen's resolution
    95.     OldX = Screen.Width / Screen.TwipsPerPixelX
    96.     OldY = Screen.Height / Screen.TwipsPerPixelY
    97.     'Create a device context, compatible with the screen
    98.     nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
    99.     'Change the screen's resolution
    100.     ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL)
    101. End Sub

  3. #3
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Hack, you make it WAY too easy =P.

    Z.

  4. #4

    Thread Starter
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    Thanks that worked great

    is that the simplest way to do it thought??

    that looks prety complex and thier are some things in the code like:

    Public Const EWX_LOGOFF = 0
    Public Const EWX_SHUTDOWN = 1
    Public Const EWX_REBOOT = 2

    If an = vbYes Then
    erg& =ExitWindowsEx(EWX_REBOOT, 0&)
    End If

    thoes code snipits seem to be used to shut down the computer are they nesisary i dont know any computer that need to be shut down to change the res mabye real old ones do though

    and also how do i get it to make the code i type in the post form message look like code

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    With a Microsoft product, you can even change your mind unless you reboot.

    In terms of formatting your posts, see the link in my signature.

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Originally posted by dogfish227
    Thanks that worked great

    is that the simplest way to do it thought??

    that looks prety complex and thier are some things in the code like:

    Public Const EWX_LOGOFF = 0
    Public Const EWX_SHUTDOWN = 1
    Public Const EWX_REBOOT = 2

    If an = vbYes Then
    erg& =ExitWindowsEx(EWX_REBOOT, 0&)
    End If
    Using those functions are the easiest.

    Yes, you could always remove the shutdown code, and the comments if you really want to shorten your code. You can also remove the constants that are not in use.

  7. #7

    Thread Starter
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    ok thanks for the help with the res

    but i still dont know how to make the code on the form look like code
    i tried useing the "[code ]" tag but that is for code in genal it dosent change the colors:
    Code:
    label1.caption = "Test"
    the page never atualy says how to make it look like vb code

    i tried "[vb], [visiual basic], [visiualbasic],"

    none of those worked what is the name of the tag

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    [vbcode][/Highlight]
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    VB Code:
    1. Dim Worked as boolean
    2. Worked = true 'it worked

  10. #10
    Junior Member
    Join Date
    Nov 2002
    Posts
    23
    Can anyone tell me what this line of code actually does?
    VB Code:
    1. DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    I found the code reset my refresh rate to 60Hz even with:
    VB Code:
    1. DevM.dmDisplayFrequency = 75
    included in the code.
    I commented out the top line and now it works without a problem, I've not removed something important have I?

    ta.
    - Mike.

  11. #11
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Originally posted by MikeAJK
    Can anyone tell me what this line of code actually does?
    VB Code:
    1. DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    You fill in the dmFields property to let Windows know what other properties you are going to be using.

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