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




Reply With Quote