|
-
Apr 30th, 2002, 05:13 AM
#1
Thread Starter
New Member
changing the screen resolution
The example provided on this site unfortunately does not migrate well to .net. The main sticking point is that .net has removed the ability to declare a type as "any" - which is exactly what the DEVMODE structure needs. The help goes on about overloading a declaration - which seems like a ridiculous way to do things, and does not work in this case.
Does anyone have a nice and easy fix for this? (Code follows)
Option Strict Off
Option Explicit On
Module modDynamicChange
Private Const CCDEVICENAME As Short = 32
Private Const CCFORMNAME As Short = 32
Private Const DISP_CHANGE_SUCCESSFUL As Short = 0
Private Const DISP_CHANGE_RESTART As Short = 1
Private Const DISP_CHANGE_FAILED As Short = -1
Private Const DISP_CHANGE_BADMODE As Short = -2
Private Const DISP_CHANGE_NOTUPDATED As Short = -3
Private Const DISP_CHANGE_BADFLAGS As Short = -4
Private Const DISP_CHANGE_BADPARAM As Short = -5
Private Const CDS_UPDATEREGISTRY As Short = &H1s
Private Const CDS_TEST As Short = &H2s
Private Const DM_BITSPERPEL As Integer = &H40000
Private Const DM_PELSWIDTH As Integer = &H80000
Private Const DM_PELSHEIGHT As Integer = &H100000
Private Structure DEVMODE '!!! Structure here needs DEVMODE to be declared as any
<VBFixedString(CCDEVICENAME),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices .UnmanagedType.ByValTStr,SizeConst:=CCDEVICENAME)> Public dmDeviceName As String
Dim dmSpecVersion As Short
Dim dmDriverVersion As Short
Dim dmSize As Short
Dim dmDriverExtra As Short
Dim dmFields As Integer
Dim dmOrientation As Short
Dim dmPaperSize As Short
Dim dmPaperLength As Short
Dim dmPaperWidth As Short
Dim dmScale As Short
Dim dmCopies As Short
Dim dmDefaultSource As Short
Dim dmPrintQuality As Short
Dim dmColor As Short
Dim dmDuplex As Short
Dim dmYResolution As Short
Dim dmTTOption As Short
Dim dmCollate As Short
<VBFixedString(CCFORMNAME),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.U nmanagedType.ByValTStr,SizeConst:=CCFORMNAME)> Public dmFormName As String
Dim dmUnusedPadding As Short
Dim dmBitsPerPel As Short
Dim dmPelsWidth As Integer
Dim dmPelsHeight As Integer
Dim dmDisplayFlags As Integer
Dim dmDisplayFrequency As Integer
End Structure
'!!!THE PROBLEM IS ON THE LINE BELOW - lpDevMode as ANY
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, ByRef lpDevMode As Any) As Boolean
'!!!!THE PROBLEM IS ON THE LINE BELOW - lpDevMode as ANY
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As Any, ByVal dwflags As Integer) As Integer
Function ChangeScreenSettings(ByRef lWidth As Short, ByRef lHeight As Short, ByRef lColors As Short) As Object
Dim tDevMode As DEVMODE
Dim lTemp, lIndex As Integer
' Declare variables
lIndex = 0
Do
'Instilise Do loop
'UPGRADE_WARNING: Couldn't resolve default property of object tDevMode. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'
lTemp = EnumDisplaySettings(0, lIndex, tDevMode)
' Call the APi function
If lTemp = 0 Then Exit Do
' If there is no more data or an erro occurs
' then return 0 and exit do
lIndex = lIndex + 1
' Increase the index to be enumerated
With tDevMode
If .dmPelsWidth = lWidth And .dmPelsHeight = lHeight And .dmBitsPerPel = lColors Then
'UPGRADE_WARNING: Couldn't resolve default property of object tDevMode. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'
lTemp = ChangeDisplaySettings(tDevMode, CDS_UPDATEREGISTRY)
Exit Do
End If
End With
' Set the new data
' Change the display type. This depends on the paramter used
' It can either be:
' 0 - Dynamic change if possible
' CDS_UPDATEREGISTRY - Dynamically change if possible
' and if not possibel then update registry for change
' on the next boot-up
' CDS_TEST - Test the new settings
Loop
Select Case lTemp
' Check for errors
Case DISP_CHANGE_SUCCESSFUL
MsgBox("The display settings change was successful", MsgBoxStyle.Information)
Case DISP_CHANGE_RESTART
MsgBox("The computer must be restarted in order for the graphics mode to work", MsgBoxStyle.Question)
Case DISP_CHANGE_FAILED
MsgBox("The display driver failed the specified graphics mode", MsgBoxStyle.Critical)
Case DISP_CHANGE_BADMODE
MsgBox("The graphics mode is not supported", MsgBoxStyle.Critical)
Case DISP_CHANGE_NOTUPDATED
MsgBox("Unable to write settings to the registry", MsgBoxStyle.Critical)
' NB. Windows NT Only
Case DISP_CHANGE_BADFLAGS
MsgBox("An invalid set of flags was passed in", MsgBoxStyle.Critical)
End Select
End Function
End Module
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|