Results 1 to 5 of 5

Thread: <?>

  1. #1

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    I am using this to change settings.
    In my form activate i check to see if the settings are > 800 x 600 
    If they are then I call sResolute and change them to 800 x 600 and
    at the same time I store the current settings to be used in sResetResolute
    
    It changes form 1024 x 728  to 800 x 600 without any problem.
    In the querryUnload and my unload of forms I call sResetResolute but
    it does not reset the settings. I have checked the variables I am passing
    and they are 1074 x 728. I've even hardcoded them...
    
    Anyone "
    
    
    
    Public Declare Function ChangeDisplaySettings Lib "user32.dll" _
    Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
    
    Public Declare Function EnumDisplaySettings Lib "user32.dll" _
    Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, _
    ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long
    
    Public Const ENUM_CURRENT_SETTINGS = -1
    
    
    Public Const CDS_UPDATEREGISTRY = &H1
    Public Const CDS_TEST = &H2
    Public Const CDS_FULLSCREEN = &H4
    Public Const CDS_GLOBAL = &H8
    Public Const CDS_SET_PRIMARY = &H10
    Public Const CDS_RESET = &H40000000
    Public Const CDS_SETRECT = &H20000000
    Public Const CDS_NORESET = &H10000000
    Public Const DISP_CHANGE_SUCCESSFUL = 0
    Public Const DISP_CHANGE_RESTART = 1
    Public Const DISP_CHANGE_FAILED = -1
    Public Const DISP_CHANGE_BADMODE = -2
    Public Const DISP_CHANGE_NOTUPDATED = -3
    Public Const DISP_CHANGE_BADFLAGS = -4
    Public Const DISP_CHANGE_BADPARAM = -5
    
    ' Declarations and such needed for the example:
    ' (Copy them to the (declarations) section of a module.)
    Public Type DEVMODE
        dmDeviceName As String * 32
        dmSpecVersion As Integer
        dmDriverVersion As Integer
        dmSize As Integer
        dmDriverExtra As Integer
        dmFields As Long
        dmOrientation As Integer
        dmPaperSize As Integer
        dmPaperLength As Integer
        dmPaperWidth As Integer
        dmScale As Integer
        dmCopies As Integer
        dmDefaultSource As Integer
        dmPrintQuality As Integer
        dmColor As Integer
        dmDuplex As Integer
        dmYResolution As Integer
        dmTTOption As Integer
        dmCollate As Integer
        dmFormName As String * 32
        dmUnusedPadding As Integer
        dmBitsPerPixel As Integer
        dmPelsWidth As Long
        dmPelsHeight As Long
        dmDisplayFlags As Long
        dmDisplayFrequency As Long
        ' The following only appear in Windows 95, 98, 2000
        dmICMMethod As Long
        dmICMIntent As Long
        dmMediaType As Long
        dmDitherType As Long
        dmReserved1 As Long
        dmReserved2 As Long
        ' The following only appear in Windows 2000
        dmPanningWidth As Long
        dmPanningHeight As Long
    End Type
    
    
    Public Sub sResolute()
        Dim dm As DEVMODE   ' display settings
        Dim retval As Long  ' return value
        
        ' Initialize the structure that will hold the settings.
        dm.dmSize = Len(dm)
        ' Get the current display settings.
        retval = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)
        ' Change the resolution settings to 800x600.
        dm.dmPelsWidth = 800
        dm.dmPelsHeight = 600
        ' Test to make sure the changes are possible.
        retval = ChangeDisplaySettings(dm, CDS_TEST)
        If retval <> DISP_CHANGE_SUCCESSFUL Then
            Debug.Print "Cannot change to that resolution!"
        Else
            ' Change and save to the new settings.
            retval = ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY)
            Select Case retval
            Case DISP_CHANGE_SUCCESSFUL
                Debug.Print "Resolution successfully changed!"
            Case DISP_CHANGE_RESTART
                Debug.Print "A reboot is necessary before the changes will take effect."
            Case Else
                Debug.Print "Unable to change resolution!"
            End Select
        End If
    End Sub
    color=red]
    '**********************************************************************
    'for some reason this will not reset the settings.
    'it's the same sub but it doesn't work.
    'I even hardcoded the size 
    
    Public Sub sResetResolute() [/color]
        Dim dm As DEVMODE   ' display settings
        Dim retval As Long  ' return value
        
        ' Initialize the structure that will hold the settings.
        dm.dmSize = Len(dm)
        ' Get the current display settings.
        retval = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)
        ' Change the resolution settings to 800x600.
        dm.dmPelsWidth = 1074 'CInt(userWidth)
        dm.dmPelsHeight = 768 'CInt(userHeight)
        ' Test to make sure the changes are possible.
        retval = ChangeDisplaySettings(dm, CDS_TEST)
        If retval <> DISP_CHANGE_SUCCESSFUL Then
            Debug.Print "Cannot change to that resolution!"
        Else
            ' Change and save to the new settings.
            retval = ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY)
            Select Case retval
            Case DISP_CHANGE_SUCCESSFUL
                Debug.Print "Resolution successfully changed!"
            Case DISP_CHANGE_RESTART
                Debug.Print "A reboot is necessary before the changes will take effect."
            Case Else
                Debug.Print "Unable to change resolution!"
            End Select
        End If
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  2. #2
    jim mcnamara
    Guest
    In the reset module, what do you get for retval?


    I'd also suggest changing some of your declarations -

    Public Declare Function ChangeDisplaySettings Lib "user32.dll" _
    Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

    To:
    Public Declare Function ChangeDisplaySettings Lib "user32.dll" _
    Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As Long, ByVal dwFlags As Long) As Long.

    The As Any thing has killed me before.

  3. #3

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Thanks Jim...Your answer sparked me into a few more tests and after changing the anything I fired in the hardcoded dimensions and presto it worked.

    Changed the ref to devmode instead of anything and went in and double checked my values. I should be ashamed to say this but my values were indeed correct....except...I had them reversed in the storage variable..ie 1024 x 768 as 768 x 1024....no wonder I couldn't get it to work....In my defense, it was 5:00 am after being up all night with my granddaughter so Fatigue has to be factered in...LOL..

    retval = 1

    Public Declare Function ChangeDisplaySettings Lib "user32.dll" _
    Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As Devmode, ByVal dwFlags As Long) As Long.

    ..right now the only thing I don't like is that it flashes the screed twice before doing the conversion...but I'll do a little more testing on the matter and include a form level message or something so the user doesn't panic with the thought that I just killed his precious little pc.

    Later,
    Wayne
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    As an afterthought...is there anything else I should be mindful of when changing a persons settings in this manner.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    jim mcnamara
    Guest
    A lot of games mess with settings, and when the code abends or somebody pushes the windows key or alt-tab (for example), the user is sometimes left with a wierd-looking screen.

    You really better be sure that, with the exception of errors you can't handle, you cannot get out of the app without at least trying to reset the resolution. This is a challenge. Which is why most shops don't allow that kind of thing for production code.

    If this isn't a game, why mess with resolution? Are you using a 6 point font or something...

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