Windows API Guide: auxGetNumDevs Function


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

Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.5 or later.
  • Windows 2000: Supported.
  • Windows CE: Not Supported.

Description & Usage

ChangeDisplaySettings changes the current display settings. This function can change the current screen resolution and color depth, among other things. Typically, a call to EnumDisplaySettings should preceed this function, in order to adjust only the desired settings.

Return Value

The function returns one of the following flags:

DISP_CHANGE_SUCCESSFUL
The display settings were successfully changed.
DISP_CHANGE_RESTART
The computer must be restarted for the display changes to take effect.
DISP_CHANGE_BADFLAGS
An invalid set of flags was specified.
DISP_CHANGE_BADPARAM
An invalid parameter was specified.
DISP_CHANGE_FAILED
The display driver failed the specified graphics mode.
DISP_CHANGE_BADMODE
The specified graphics mode is not supported.
DISP_CHANGE_NOTUPDATED
Windows NT/2000: The settings could not be written to the registry.

Visual Basic-Specific Issues

When specifying zero for lpDevMode, use the expression ByVal CLng(0).

Parameters

lpDevMode
A DEVMODE structure that holds the new display settings. Only the dmBitsPerPixel, dmPelsWidth, dmPelsHeight, dmDisplayFlags, and dmDisplayFrequency members are used. (Windows 98, NT/2000: The dmPosition member can also be used.) To restore the settings saved in the registry, set this parameter and dwFlags to zero.
dwFlags
A combination of the following flags specifying how to change the display mode. If no flags are set (i.e., zero is specified), the graphics mode is changed dynamically.
CDS_UPDATEREGISTRY
Save the new settings to the registry and also change the settings dynamically.
CDS_TEST
Test to see if the new settings are supported by the hardware, without actually changing the settings. The function's return value will indicate any problems that may have occured.
CDS_FULLSCREEN
Go into full-screen mode. This setting cannot be saved.
CDS_GLOBAL
Save the new settings for all users. The CDS_UPDATEREGISTRY flag must also be specified.
CDS_SET_PRIMARY
Make this device the primary display device.
CDS_RESET
Change the settings even if they are the same as the current settings.
CDS_NORESET
Save the settings to the registry, but do not make them take effect yet. The CDS_UPDATEREGISTRY flag must also be specified.

Constant Definitions

Const CDS_UPDATEREGISTRY = &H1 Const CDS_TEST = &H2 Const CDS_FULLSCREEN = &H4 Const CDS_GLOBAL = &H8 Const CDS_SET_PRIMARY = &H10 Const CDS_RESET = &H40000000 Const CDS_SETRECT = &H20000000 Const CDS_NORESET = &H10000000 Const DISP_CHANGE_SUCCESSFUL = 0 Const DISP_CHANGE_RESTART = 1 Const DISP_CHANGE_FAILED = -1 Const DISP_CHANGE_BADMODE = -2 Const DISP_CHANGE_NOTUPDATED = -3 Const DISP_CHANGE_BADFLAGS = -4 Const DISP_CHANGE_BADPARAM = -5

Example

Change the current screen resolution to 800x600 without changing the color depth and save the changes to the registry. First test to make sure that the hardware supports the new resolution. If a reboot is necessary, inform the user. To use this example, place a command button named Command1 of a form window.

' This code is licensed according to the terms and conditions listed here. ' 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 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 Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags _ As Long) As Long Public Const CDS_UPDATEREGISTRY = &H1 Public Const CDS_TEST = &H2 Public Const DISP_CHANGE_SUCCESSFUL = 0 Public Const DISP_CHANGE_RESTART = 1 ' *** Place the following code inside the form window. Private Sub Command1_Click() 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

See Also

EnumDisplaySettings

Category

Devices

Back to the Function list.
Back to the Reference section.


Last Modified: January 21, 2001
This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/changedisplaysettings.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net