Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than coredll, prefix the name with the module name and a period.
changedisplaysettingsex (coredll)
coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for changedisplaysettingsex in other DLLs exists, click on Find References to the right.
.
VB Signature:
Declare Function ChangeDisplaySettingsEx Lib "coredll.dll" (ByVal lpszDeviceName As String, ByVal lpDevMode As Byte(), ByVal hwnd As IntPtr, ByVal dwflags As CDSFlags, ByVal lParam As IntPtr) As CDSRet
User-Defined Types:
Public Enum DMD
DMDO_0 = 0
DMDO_90 = 1
DMDO_180 = 2
DMDO_270 = 4
End Enum
Public Enum DM_Fields
DM_DISPLAYORIENTATION = 8388608
DM_DISPLAYQUERYORIENTATION = 16777216
End Enum
Public Enum DM_Orient
DMORIENT_PORTRAIT = 1
DMORIENT_LANDSCAPE = 2
End Enum
' Flags for ChangeDisplaySettings
Enum CDSFlags
CDS_VIDEOPARAMETERS = &H20
CDS_RESET = &H40000000
End Enum
Public Sub New(ByVal size As Integer)
m_data = New Byte(size - 1) {}
End Sub
Public Function GetChar(ByVal offset As Integer) As Char
Return BitConverter.ToChar(m_data, offset)
End Function
Public Sub SetChar(ByVal offset As Integer, ByVal val As Char)
Buffer.BlockCopy(BitConverter.GetBytes(val), 0, m_data, offset, 2)
End Sub
Public Function GetInt32(ByVal offset As Integer) As Int32
Return BitConverter.ToInt32(m_data, offset)
End Function
Public Sub SetInt32(ByVal offset As Integer, ByVal val As Int32)
Buffer.BlockCopy(BitConverter.GetBytes(val), 0, m_data, offset, 4)
End Sub
Public Function GetUInt32(ByVal offset As Integer) As UInt32
Return BitConverter.ToUInt32(m_data, offset)
End Function
Public Sub SetUInt32(ByVal offset As Integer, ByVal val As UInt32)
Buffer.BlockCopy(BitConverter.GetBytes(val), 0, m_data, offset, 4)
End Sub
Public Function GetInt16(ByVal offset As Integer) As Int16
Return BitConverter.ToInt16(m_data, offset)
End Function
Public Sub SetInt16(ByVal offset As Integer, ByVal val As Int16)
Buffer.BlockCopy(BitConverter.GetBytes(val), 0, m_data, offset, 2)
End Sub
Public Function GetUInt16(ByVal offset As Integer) As UInt16
Return BitConverter.ToUInt16(m_data, offset)
End Function
Public Sub SetUInt16(ByVal offset As Integer, ByVal val As UInt16)
Buffer.BlockCopy(BitConverter.GetBytes(val), 0, m_data, offset, 2)
End Sub
Public Function GetStringUni(ByVal offset As Integer, ByVal len As Integer) As String
Return Encoding.Unicode.GetString(m_data, offset, len).TrimEnd(Chr(0))
End Function
Public Sub SetStringUni(ByVal str As String, ByVal offset As Integer, ByVal len As Integer)
Encoding.Unicode.GetBytes(str, 0, Math.Min(str.Length, len), m_data, offset)
End Sub
Default Public Property Item(ByVal offset As Integer) As Byte
Get
Return m_data(offset)
End Get
Set(ByVal value As Byte)
m_data(offset) = value
End Set
End Property
Public Function [Get](ByVal t As Type, ByVal offset As Integer) As Object
If t.IsPrimitive Then
If t.BaseType.ToString = "Int32" Then
Return GetInt32(offset)
ElseIf t.BaseType.ToString = "Int16" Then
Return GetInt16(offset)
ElseIf t.BaseType.ToString = "UInt32" Then
Return GetUInt32(offset)
ElseIf t.BaseType.ToString = "UInt16" Then
Return GetUInt16(offset)
ElseIf t.BaseType.ToString = "Byte" Then
Return Me(offset)
End If
End If
Return Nothing
End Function
Public Sub [Set](ByVal t As Type, ByVal offset As Integer, ByVal Val As Object)
If t.IsPrimitive Then
If t.BaseType.ToString = "Int32" Then
SetInt32(offset, CInt(Val))
ElseIf t.BaseType.ToString = "Int16" Then
SetInt16(offset, CShort(Val))
ElseIf t.BaseType.ToString = "UInt32" Then
SetUInt32(offset, DirectCast(Val, UInt32))
ElseIf t.BaseType.ToString = "UInt16" Then
SetUInt16(offset, CUShort(Val))
ElseIf t.BaseType.ToString = "Byte" Then
Me(offset) = CByte(Val)
End If
ElseIf t.ToString = "String" Then
SetStringUni(DirectCast(Val, String), offset, DirectCast(Val, String).Length)
End If
End Sub
Protected m_data As Byte()
Public ReadOnly Property Data() As Byte()
Get
Return m_data
End Get
End Property
End Class
Public Class devicemodeW
Inherits SelfMarshalledStruct
Private _DM_Orient As DM_Orient
Private _DM_Fields As DM_Fields
Private _DMD As DMD
Public Sub New()
MyBase.New(192)
dmSize = CUShort(Data.Length)
End Sub
Public Property dmDeviceName() As String
Get
Return GetStringUni(0, 64)
End Get
Set(ByVal value As String)
SetStringUni(value, 0, 64)
End Set
End Property
Public Property dmSpecVersion() As UShort
Get
Return GetUInt16(64)
End Get
Set(ByVal value As UShort)
SetUInt16(64, value)
End Set
End Property
Public Property dmDriverVersion() As UShort
Get
Return GetUInt16(66)
End Get
Set(ByVal value As UShort)
SetUInt16(66, value)
End Set
End Property
Public Property dmSize() As UShort
Get
Return GetUInt16(68)
End Get
Set(ByVal value As UShort)
SetUInt16(68, value)
End Set
End Property
Public Property dmDriverExtra() As UShort
Get
Return GetUInt16(70)
End Get
Set(ByVal value As UShort)
SetUInt16(70, value)
End Set
End Property
Public Property dmFields() As DM_Fields
Get
'Return DirectCast(GetUInt32(72), DM_Fields)
Return _DM_Fields
End Get
Set(ByVal value As DM_Fields)
_DM_Fields = value
SetUInt32(72, CInt(value))
End Set
End Property
Public Property dmOrientation() As DM_Orient
Get
'Return DirectCast(GetInt16(76), DM_Orient)
Return _DM_Orient
End Get
Set(ByVal value As DM_Orient)
SetInt16(76, CShort(value))
End Set
End Property
Public Property dmPaperSize() As Short
Get
Return GetInt16(78)
End Get
Set(ByVal value As Short)
SetInt16(78, value)
End Set
End Property
Public Property dmPaperLength() As Short
Get
Return GetInt16(80)
End Get
Set(ByVal value As Short)
SetInt16(80, value)
End Set
End Property
Public Property dmPaperWidth() As Short
Get
Return GetInt16(82)
End Get
Set(ByVal value As Short)
SetInt16(82, value)
End Set
End Property
Public Property dmScale() As Short
Get
Return GetInt16(84)
End Get
Set(ByVal value As Short)
SetInt16(84, value)
End Set
End Property
Public Property dmCopies() As Short
Get
Return GetInt16(86)
End Get
Set(ByVal value As Short)
SetInt16(86, value)
End Set
End Property
Public Property dmDefaultSource() As Short
Get
Return GetInt16(88)
End Get
Set(ByVal value As Short)
SetInt16(88, value)
End Set
End Property
Public Property dmPrintQuality() As Short
Get
Return GetInt16(90)
End Get
Set(ByVal value As Short)
SetInt16(90, value)
End Set
End Property
Public Property dmColor() As Short
Get
Return GetInt16(92)
End Get
Set(ByVal value As Short)
SetInt16(92, value)
End Set
End Property
Public Property dmDuplex() As Short
Get
Return GetInt16(94)
End Get
Set(ByVal value As Short)
SetInt16(94, value)
End Set
End Property
Public Property dmYResolution() As Short
Get
Return GetInt16(96)
End Get
Set(ByVal value As Short)
SetInt16(96, value)
End Set
End Property
Public Property dmTTOption() As Short
Get
Return GetInt16(98)
End Get
Set(ByVal value As Short)
SetInt16(98, value)
End Set
End Property
Public Property dmCollate() As Short
Get
Return GetInt16(100)
End Get
Set(ByVal value As Short)
SetInt16(100, value)
End Set
End Property
Public Property dmFormName() As String
Get
Return GetStringUni(102, 64)
End Get
Set(ByVal value As String)
SetStringUni(value, 102, 64)
End Set
End Property
Public Property dmLogPixels() As UShort
Get
Return GetUInt16(166)
End Get
Set(ByVal value As UShort)
SetUInt16(166, value)
End Set
End Property
Public Property dmBitsPerPel() As UInteger
Get
Return GetUInt32(168)
End Get
Set(ByVal value As UInteger)
SetUInt32(168, value)
End Set
End Property
Public Property dmPelsWidth() As UInteger
Get
Return GetUInt32(172)
End Get
Set(ByVal value As UInteger)
SetUInt32(172, value)
End Set
End Property
Public Property dmPelsHeight() As UInteger
Get
Return GetUInt32(176)
End Get
Set(ByVal value As UInteger)
SetUInt32(176, value)
End Set
End Property
Public Property dmDisplayFlags() As UInteger
Get
Return GetUInt32(180)
End Get
Set(ByVal value As UInteger)
SetUInt32(180, value)
End Set
End Property
Public Property dmDisplayFrequency() As UInteger
Get
Return GetUInt32(184)
End Get
Set(ByVal value As UInteger)
SetUInt32(184, value)
End Set
End Property
Public Property dmDisplayOrientation() As DMD
Get
'Return DirectCast(GetUInt32(188), DMD)
Return _DMD
End Get
Set(ByVal value As DMD)
_DMD = value
SetUInt32(188, CInt(value))
End Set
End Property
End Class
Public Class ScreenMode
'DEVICEMODE
<DllImport("coredll.dll")> _
Friend Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, ByVal lpDevMode As Byte(), ByVal hwnd As IntPtr, ByVal dwflags As CDSFlags, ByVal lParam As IntPtr) As CDSRet
End Function
Public Function ChangeMode(ByVal degree As Integer) As String
Dim devMode As New devicemodeW()
devMode.dmFields = DM_Fields.DM_DISPLAYORIENTATION
If degree = 0 Then
devMode.dmDisplayOrientation = DMD.DMDO_0
ElseIf degree = 90 Then
devMode.dmDisplayOrientation = DMD.DMDO_90
ElseIf degree = 180 Then
devMode.dmDisplayOrientation = DMD.DMDO_180
ElseIf degree = 270 Then
devMode.dmDisplayOrientation = DMD.DMDO_270
End If
Dim ret As CDSRet = ChangeDisplaySettingsEx(Nothing, devMode.Data, IntPtr.Zero, 0, IntPtr.Zero)
Return (ret.ToString())
End Function
Public Sub SetLandscape()
Try
ChangeMode(90)
Catch ex As Exception
'MsgBox(ex.ToString)
End Try
End Sub
Public Sub SetPortrait()
Try
ChangeMode(0)
Catch ex As Exception
'MsgBox(ex.ToString)
End Try
End Sub
End Class
C# Sample Code(it's directlly convert from the VB.net Code via conversion tool-RRave)
public class SelfMarshalledStruct
{
public SelfMarshalledStruct(int size)
{
m_data = new byte[size];
}
public char GetChar(int offset)
{
return BitConverter.ToChar(m_data, offset);
}
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).