ChangeDisplaySettings() Does Not Work Properly---Help!!!

ChangeDisplaySettings() Does Not Work Properly---Help!!!

Post by John Yeag » Fri, 20 Jun 1997 04:00:00



The following code produces a screen flash but does not actually
change the screen rez.... Anyone out there done this correctly?

(BTW, the code that changes the screen rez only executes if you are in
a screen rez OTHER than 800x600.)

'*****************************************************************
 ' DECLARATIONS SECTION
 '*****************************************************************
      Option Explicit

      Type RECT
          x1 As Long
          y1 As Long
          x2 As Long
          y2 As Long
      End Type

      Type DEVMODE
          dmFields     As Long
          dmBitsPerPel As Long
          dmPelsWidth  As Long
          dmPelsHeight As Long
          dmDisplayFlags As Long
          dmDisplayFrequency As Long
      End Type

      Public Const DM_BITSPERPEL = &H40000
      Public Const DM_PELSWIDTH = &H80000
      Public Const DM_PELSHEIGHT = &H100000
      Public Const DM_DISPLAYFLAGS = &H200000
      Public Const DM_DISPLAYFREQUENCY = &H400000
      Public Const DISP_CHANGE_FAILED = -1
      Public Const DISP_CHANGE_BADMODE = -2
      Public Const DISP_CHANGE_BADFLAGS = -4
      Public Const DISP_CHANGE_SUCCESSFUL = 0
      Public Const DISP_CHANGE_RESTART = 1

      ' NOTE: The following declare statements are case sensitive.
      Declare Function EnumDisplaySettingsA Lib "User32" _
         (ByVal vidstr As String, ByVal vidnum As Long, ByRef mymode
As DEVMODE) As Long
      Declare Function ChangeDisplaySettingsA Lib "User32" _
         (ByRef mymode As DEVMODE, ByVal myflags As Long) As Long
      Declare Function GetDesktopWindow Lib "User32" () As Long
      Declare Function GetWindowRect Lib "User32" _
         (ByVal hWnd As Long, rectangle As RECT) As Long

'*****************************************************************
      ' FUNCTION: GetScreenResolution()
      '
      ' PURPOSE:
      '   To determine the current screen size or resolution.
      '
      ' RETURN:
      '   The current screen resolution. Typically one of the
following:
      '      640 x 480
      '      800 x 600
      '      1024 x 768
      '

'*****************************************************************
      Function GetScreenResolution() As String
          Dim R As RECT
          Dim D As DEVMODE
          Dim hWnd As Long
          Dim RetVal As Long
          Dim RetVal2 As Long
          Dim tf As Boolean
          Dim x As Integer

          tf = True
          x = 0

          D.dmBitsPerPel = 16       '16 bit mode
          D.dmPelsWidth = 800       'Horizontal Res
          D.dmPelsHeight = 600      'Vertical Res
          D.dmDisplayFlags = 0      'Standard NON Interlaced Color
Display
          D.dmDisplayFrequency = 60 'Screen Display Frequency

          D.dmFields = DM_BITSPERPEL Or DM_PELSWIDTH Or DM_PELSHEIGHT
Or DM_DISPLAYFLAGS Or DM_DISPLAYFREQUENCY

          hWnd = GetDesktopWindow()
          RetVal = GetWindowRect(hWnd, R)
          GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)

          If GetScreenResolution <> "800x600" Then
            Do Until tf = False
              x = x + 1
              tf = EnumDisplaySettingsA(Chr(0), x, D)
            Loop
            RetVal2 = ChangeDisplaySettingsA(D, 0)
            If RetVal2 = DISP_CHANGE_FAILED Then
                MsgBox "Could Not Change Screen Res... Display Driver
Cannot Switch To This Graphics Mode"
            End If
            If RetVal2 = DISP_CHANGE_BADMODE Then
                MsgBox "Could Not Change Screen Res... This Graphics
Mode Is Not Supported"
            End If
            If RetVal2 = DISP_CHANGE_BADFLAGS Then
                MsgBox "Could Not Change Screen Res... Invalid Flags
Set"
            End If
            If RetVal2 = DISP_CHANGE_SUCCESSFUL Then
                'MsgBox "Screen Res Changed"
            End If
            If RetVal2 = DISP_CHANGE_RESTART Then
                MsgBox "Computer Needs To Be Restarted"
            End If
          End If
      End Function

' 2.On the View menu, click Debug window.

' 3.Type the following line in the Debug window, and then press ENTER:

'      Print GetScreenResolution()

' Note that the current screen resolution is displayed in the Debug
window.
' If the current resolution is standard VGA, the following is
displayed in
' the Debug window:

' 640 x480

 
 
 

1. Help! Boolean operation does not work properly

Does anyone know what to do if Boolean subtraction of two objects does not
work?
It seems to me that sometimes two objects are too complicated for the
operation, but
sometimes it does not work with relatively simple objects.
If someone knows a trick to go around, please help.
Dima Mozzherin

2. MPEG to AVI

3. Rage Fury Maxx not working properly with xp

4. seeking scriptable graphics database

5. Actions not Working Properly ... Important

6. Layers with OpenGL ?

7. File save and CTL S not working properly

8. area optimisation?

9. Zoom Tool Not Working Properly?

10. Text Tool not working properly

11. texture mapping not working properly with the release copy from VC++ 6.0

12. SGI-Ogl and glIndexFunc not working properly

13. Fog not working properly