Saturday, November 21, 2009
 
    Search Web Link
Search Software
    
API Home » Display » ChangeDisplaySettingsEx

ChangeDisplaySettingsEx

Category: Display
Hits: 4849 Rating: ChangeDisplaySettingsEx has been rated 3.19 by  747 users (3.19) votes 747
Rate: 1-star  2-stars  3-stars  4-stars  5-stars
E-mail this API to friend E-mail this Code to a friend  save Bookmark this VB API Function
API Explanation
The ChangeDisplaySettingsEx function changes the settings of the display device specified in the lpszDeviceName parameter to the graphics mode specified in the lpDevMode parameter.

Parameter Information
Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long

· lpszDeviceName
[in] Pointer to a null-terminated string that specifies the display device whose graphics mode the function will obtain information about. Only display device names as returned by EnumDisplayDevices are valid. See EnumDisplayDevices for further information on the names associated with these display devices.
The lpszDeviceName parameter can be NULL. A NULL value specifies the default display device. The default device can be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag.

· lpDevMode
[in] Pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags parameter is the easiest way to return to the default mode after a dynamic mode change.
The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure. In addition, you can use any of the following members of the DEVMODE structure.
dmBitsPerPel
Bits per pixel
dmPelsWidth
Pixel width
dmPelsHeight
Pixel height
dmDisplayFlags
Mode flags
dmDisplayFrequency
Mode frequency
dmPosition
Windows 98, Windows 2000: Position of the device in a multi-monitor configuration.

In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the dmFields member to change the display settings.
DM_BITSPERPEL
Use the dmBitsPerPel value.
DM_PELSWIDTH
Use the dmPelsWidth value.
DM_PELSHEIGHT
Use the dmPelsHeight value.
DM_DISPLAYFLAGS
Use the dmDisplayFlags value.
DM_DISPLAYFREQUENCY
Use the dmDisplayFrequency value.
DM_POSITION
Windows 98, Windows 2000: Use the dmPosition value.

· hwnd
Reserved; must be NULL.

· dwflags
[in] Indicates how the graphics mode should be changed. This parameter can be one of the following values.
0
The graphics mode for the current screen will be changed dynamically.
CDS_FULLSCREEN
The mode is temporary in nature.
Windows NT/2000: If you change to and from another desktop, this mode will not be reset.
CDS_GLOBAL
The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.
CDS_NORESET
The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.
CDS_RESET
The settings should be changed, even if the requested settings are the same as the current settings.
CDS_SET_PRIMARY
This device will become the primary device.
CDS_TEST
The system tests if the requested graphics mode could be set.
CDS_UPDATEREGISTRY
The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The mode information is stored in the USER profile.
CDS_VIDEOPARAMETERS
Windows NT/2000: When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure.

Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to change to them.

If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_RESTART is returned.

Windows NT/2000: If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and DISP_CHANGE_NOTUPDATED is returned.

· lParam
Windows NT/2000: [in] If dwFlags is CDS_VIDEOPARAMETERS, lParam is a pointer to a VIDEOPARAMETERS structure. Otherwise lParam must be NULL.
Code



Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_TEST = &H4

Private Type DISPLAY_DEVICE
cb As Long
DeviceName As String * 32
DeviceString As String * 128
StateFlags As Long
DeviceID As String * 128
DeviceKey As String * 128
End Type

Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
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 * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
dmICMMethod As Long 'NT 4.0
dmICMIntent As Long 'NT 4.0
dmMediaType As Long 'NT 4.0
dmDitherType As Long 'NT 4.0
dmReserved1 As Long 'NT 4.0
dmReserved2 As Long 'NT 4.0
dmPanningWidth As Long 'Win2000
dmPanningHeight As Long 'Win2000
End Type

Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long
Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused As Any, ByVal iDevNum As Long, lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Long) As Boolean

Dim OldX As Long, OldY As Long, T As Long

Private Sub Form_Load()
Dim DD As DISPLAY_DEVICE, DevM As DEVMODE
DD.cb = Len(DD)
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'First retieve some display info
If EnumDisplayDevices(ByVal 0&, 0, DD, ByVal 0&) Then
'and show it
Me.AutoRedraw = True
Me.Print "Device String:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1)
Me.Print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1)
Me.Print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1)
Me.Print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1)
Else
Me.Print "Error while retrieving Display Information"
End If
DevM.dmSize = Len(DevM)
'we want to change the horizontal and the vertical resolution
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 640
DevM.dmPelsHeight = 480
'change the display settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
T = Timer
Do: DoEvents: Loop Until Timer > T + 5
DevM.dmPelsWidth = OldX
DevM.dmPelsHeight = OldY
'change the display settings back to the old settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
End Sub




HOME | ARTICLES | MUSIC | DOWNLOADS | LINK DIRECTORY |  GAMES | TEST-QUIZZES | SITEMAP | ABOUT | HELP
Copyright © 2000 - 2007 Ex-designz. All rights reserved. Website Developed By Dexter Zafra of Myasp-net.com
Link to us | Advertisement | Contact us | Privacy Policy | Terms of use | Accessibility