|
|
|
To change resolution of your primary display device you can use ChangeDisplaySettings API but if you are working with multiple monitors and you want to change resolution of a specified monitor then you have to use ChangeDisplaySettingsEx API. You can specify Display device name while calling ChangeDisplaySettingsEx.
Step-By-Step Example
- Create a standard exe project - Add the following code in form1 |
Click here to copy the following block | 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 dmICMIntent As Long dmMediaType As Long dmDitherType As Long dmReserved1 As Long dmReserved2 As Long dmPanningWidth As Long dmPanningHeight As Long End Type
Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" ( _ lpszDeviceName As String, _ 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
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim OldXRes As Long, OldYRes As Long, T As Long Dim strDeviceName As String, DeviceNum As Integer
Private Sub Form_Load()
Dim DD As DISPLAY_DEVICE, DevM As DEVMODE DD.cb = Len(DD)
DeviceNum = 0
If EnumDisplayDevices(ByVal 0&, DeviceNum, DD, ByVal 0&) Then strDeviceName = Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1) Else MsgBox "Can not read device name" End If
OldXRes = Screen.Width / Screen.TwipsPerPixelX OldYRes = Screen.Height / Screen.TwipsPerPixelY
DevM.dmSize = Len(DevM) DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT DevM.dmPelsWidth = 640 DevM.dmPelsHeight = 480
Call ChangeDisplaySettingsEx(ByVal strDeviceName, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
Sleep 5000 DevM.dmPelsWidth = OldXRes DevM.dmPelsHeight = OldYRes
Call ChangeDisplaySettingsEx(ByVal strDeviceName, DevM, ByVal 0&, CDS_TEST, ByVal 0&) End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
 |

|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|