Option Strict On Imports System.Runtime.InteropServices Imports System.Reflection Public Class Form1 Inherits System.Windows.Forms.Form Private Panel1 As TableLayoutPanel Private WithEvents Button1, Button2, Button3 As Button Private WithEvents ListBox1, ListBox2, ListBox3 As ListBox Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Panel1 = New TableLayoutPanel() With {.Dock = DockStyle.Fill, .RowCount = 3, .ColumnCount = 2} Button1 = New Button() With {.Dock = DockStyle.Fill, .Text = "Screen.AllScreens"} Button2 = New Button() With {.Dock = DockStyle.Fill, .Text = "EnumDisplayMonitors"} Button3 = New Button() With {.Dock = DockStyle.Fill, .Text = "EnumDisplayDevices + EnumDisplaySettings"} ListBox1 = New ListBox() With {.Dock = DockStyle.Fill, .IntegralHeight = False} ListBox2 = New ListBox() With {.Dock = DockStyle.Fill, .IntegralHeight = False} ListBox3 = New ListBox() With {.Dock = DockStyle.Fill, .IntegralHeight = False} Panel1.Controls.AddRange(New Control() {Button1, ListBox1, Button2, ListBox2, Button3, ListBox3}) Panel1.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 160)) Panel1.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize)) Panel1.RowStyles.Add(New RowStyle(SizeType.Percent, 1.0F)) Panel1.RowStyles.Add(New RowStyle(SizeType.Percent, 1.0F)) Panel1.RowStyles.Add(New RowStyle(SizeType.Percent, 1.0F)) Controls.Add(Panel1) End Sub Private Delegate Function MONITORENUMPROC(hMonitor As IntPtr, hdcMonitor As IntPtr, lprcMonitor As IntPtr, dwData As IntPtr) As Boolean Private Declare Unicode Function EnumDisplayMonitors Lib "user32" (hdc As IntPtr, lprcClip As IntPtr, lpfnEnum As MONITORENUMPROC, dwData As IntPtr) As Boolean Private Enum EDDFlag None = 0 InterfaceName = 1 End Enum Private Class DISPLAY_DEVICE Public cb As Integer Public DeviceName As String Public DeviceString As String Public StateFlags As Flags Public DeviceID As String Public DeviceKey As String Public Sub New() Me.cb = Marshal.SizeOf(Me) End Sub Public Enum Flags AttachedToDesktop = &H1 MultiDriver = &H2 PrimaryDriver = &H4 MirroringDriver = &H8 VgaCompatible = &H10 Removable = &H20 UnsafeModesOn = &H80000 Disconnect = &H2000000 Remote = &H4000000 ModesPruned = &H8000000 End Enum End Class Private Declare Unicode Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesW" (lpDevice As String, iDevNum As Integer, <[In], Out> ByVal lpDisplayDevice As DISPLAY_DEVICE, dwFlags As EDDFlag) As Boolean Private Declare Unicode Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsW" (lpszDeviceName As String, iModeNum As Integer, <[In], Out> ByVal lpDevMode As IntPtr) As Boolean Private Declare Unicode Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsW" (lpszDeviceName As String, iModeNum As Integer, <[In], Out> ByVal lpDevMode As DEVMODEW_DISPLAY) As Boolean Private Declare Unicode Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsW" (lpszDeviceName As String, iModeNum As Integer, <[In], Out> ByVal lpDevMode As DEVMODEW_PRINTER) As Boolean Private Class DEVMODEW_PRINTER Public dmDeviceName As String Public dmSpecVersion As Short Public dmDriverVersion As Short Public dmSize As Short Public dmDriverExtra As Short Public dmFields As DevModeFields Public dmOrientation As Short Public dmPaperSize As Short Public dmPaperLength As Short Public dmPaperWidth As Short Public dmScale As Short Public dmCopies As Short Public dmDefaultSource As Short Public dmPrintQuality As Short Public dmColor As Short Public dmDuplex As Short Public dmYResolution As Short Public dmTTOption As Short Public dmCollate As Short Public dmFormName As String Public dmLogPixels As Short Public dmBitsPerPel As Integer Public dmPelsWidth As Integer Public dmPelsHeight As Integer Public dmNup As Integer Public dmDisplayFrequency As Integer Public dmICMMethod As Integer Public dmICMIntent As Integer Public dmMediaType As Integer Public dmDitherType As Integer Public dmReserved1 As Integer Public dmReserved2 As Integer Public dmPanningWidth As Integer Public dmPanningHeight As Integer Public Sub New() Me.dmSize = CShort(Marshal.SizeOf(Me) And &HFFFF) Me.dmDriverExtra = 0S 'Me.dmDeviceName = StrDup(32, ControlChars.NullChar) 'Me.dmFormName = StrDup(32, ControlChars.NullChar) End Sub End Class Private Class DEVMODEW_DISPLAY Public dmDeviceName As String Public dmSpecVersion As Short Public dmDriverVersion As Short Public dmSize As Short Public dmDriverExtra As Short Public dmFields As DevModeFields Public dmPosition As Point Public dmDisplayOrientation As ScreenOrientation Public dmDisplayFixedOutput As Integer Public dmColor As Short Public dmDuplex As Short Public dmYResolution As Short Public dmTTOption As Short Public dmCollate As Short Public dmFormName As String Public dmLogPixels As Short Public dmBitsPerPel As Integer Public dmPelsWidth As Integer Public dmPelsHeight As Integer Public dmDisplayFlags As Integer Public dmDisplayFrequency As Integer Public dmICMMethod As Integer Public dmICMIntent As Integer Public dmMediaType As Integer Public dmDitherType As Integer Public dmReserved1 As Integer Public dmReserved2 As Integer Public dmPanningWidth As Integer Public dmPanningHeight As Integer Public Sub New() Me.dmSize = CShort(Marshal.SizeOf(Me) And &HFFFF) Me.dmDriverExtra = 0S 'Me.dmDeviceName = StrDup(32, ControlChars.NullChar) 'Me.dmFormName = StrDup(32, ControlChars.NullChar) End Sub End Class Private Enum DevModeFields None = &H0 Orientation = &H1 PaperSize = &H2 PaperLength = &H4 PaperWidth = &H8 Scale = &H10 Position = &H20 Nup = &H40 DisplayOrientation = &H80 Copies = &H100 DefaultSource = &H200 PrintQuality = &H400 Color = &H800 Duplex = &H1000 YResolution = &H2000 TTOption = &H4000 Collate = &H8000 FormName = &H10000 LogPixels = &H20000 BitsPerpel = &H40000 PelsWidth = &H80000 PelsHeight = &H100000 DisplayFlags = &H200000 DisplayFrequency = &H400000 IcmMethod = &H800000 IcmIntent = &H1000000 MediaType = &H2000000 DitherType = &H4000000 PanningWidth = &H8000000 PanningHeight = &H10000000 DisplayFixedOutput = &H20000000 End Enum Private Const ENUM_CURRENT_SETTINGS As Integer = -1 Private Const ENUM_REGISTRY_SETTINGS As Integer = -2 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ListBox1.Items.Clear() Dim i As Integer = 0 For Each scr In Screen.AllScreens ListBox1.Items.Add("#" & CStr(i)) ListBox1.Items.Add(vbTab & "DeviceName=" & scr.DeviceName) ListBox1.Items.Add(vbTab & "Primary=" & scr.Primary.ToString()) ListBox1.Items.Add(vbTab & "BitsPerPixel=" & scr.BitsPerPixel.ToString()) ListBox1.Items.Add(vbTab & "Bounds=" & scr.Bounds.ToString()) ListBox1.Items.Add(vbTab & "WorkingArea=" & scr.WorkingArea.ToString()) i += 1 Next End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim CreateScreen As Func(Of IntPtr, IntPtr, Screen) CreateScreen = Function(monitor, hdc) DirectCast(GetType(Screen).GetConstructor(BindingFlags.NonPublic Or BindingFlags.Instance, Nothing, New Type() {GetType(IntPtr), GetType(IntPtr)}, Nothing).Invoke(New Object() {monitor, hdc}), Screen) Dim MonitorEnumProc As MONITORENUMPROC Dim i As Integer = 0 MonitorEnumProc = Function(hMonitor, hdcMonitor, lprcMonitor, dwData) ListBox2.Items.Add("#" & CStr(i)) ListBox2.Items.Add(vbTab & "HMONITOR=" & hMonitor.ToString()) If lprcMonitor <> IntPtr.Zero Then Dim rect As Rectangle = DirectCast(Marshal.PtrToStructure(lprcMonitor, GetType(Rectangle)), Rectangle) ListBox2.Items.Add(vbTab & rect.ToString()) End If Dim scr As Screen = CreateScreen(hMonitor, hdcMonitor) If scr IsNot Nothing Then ListBox2.Items.Add(vbTab & "DeviceName=" & scr.DeviceName) ListBox2.Items.Add(vbTab & "Primary=" & scr.Primary.ToString()) ListBox2.Items.Add(vbTab & "BitsPerPixel=" & scr.BitsPerPixel.ToString()) ListBox2.Items.Add(vbTab & "Bounds=" & scr.Bounds.ToString()) ListBox2.Items.Add(vbTab & "WorkingArea=" & scr.WorkingArea.ToString()) End If i += 1 Return True End Function ListBox2.Items.Clear() EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, MonitorEnumProc, IntPtr.Zero) End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim info As New DISPLAY_DEVICE() ListBox3.Items.Clear() Dim i As Integer = 0 Do While EnumDisplayDevices(Nothing, i, info, EDDFlag.InterfaceName) ListBox3.Items.Add("#" & CStr(i)) ListBox3.Items.Add(vbTab & "DeviceName=" & info.DeviceName) ListBox3.Items.Add(vbTab & "DeviceString=" & info.DeviceString) ListBox3.Items.Add(vbTab & "DeviceID=" & info.DeviceID) ListBox3.Items.Add(vbTab & "DeviceKey=" & info.DeviceKey) ListBox3.Items.Add(vbTab & "StateFlags=" & info.StateFlags.ToString("G")) Dim pDevMode As New DEVMODEW_DISPLAY() 'Dim result = EnumDisplaySettings(info.DeviceName, i, pDevMode) 'Dim result = EnumDisplaySettings(info.DeviceName, ENUM_REGISTRY_SETTINGS, pDevMode) 'Dim result = EnumDisplaySettings(info.DeviceName, ENUM_CURRENT_SETTINGS, ppDevMode) Dim result = EnumDisplaySettings(info.DeviceName, ENUM_REGISTRY_SETTINGS, pDevMode) If result Then ListBox3.Items.Add(vbTab & "dmDeviceName=" & pDevMode.dmDeviceName) ListBox3.Items.Add(vbTab & "dmDriverVersion=" & pDevMode.dmDriverVersion.ToString()) ListBox3.Items.Add(vbTab & "dmFields=" & pDevMode.dmFields.ToString("F")) If (pDevMode.dmFields And DevModeFields.Position) <> 0 Then ListBox3.Items.Add(vbTab & "dmPosition=" & pDevMode.dmPosition.ToString()) End If If (pDevMode.dmFields And DevModeFields.DisplayOrientation) <> 0 Then ListBox3.Items.Add(vbTab & "dmDisplayOrientation=" & pDevMode.dmDisplayOrientation.ToString()) End If If (pDevMode.dmFields And DevModeFields.Duplex) <> 0 Then ListBox3.Items.Add(vbTab & "dmDuplex=" & pDevMode.dmDuplex.ToString()) End If If (pDevMode.dmFields And DevModeFields.Color) <> 0 Then ListBox3.Items.Add(vbTab & "dmColor=" & pDevMode.dmColor.ToString()) End If If (pDevMode.dmFields And DevModeFields.YResolution) <> 0 Then ListBox3.Items.Add(vbTab & "dmYResolution=" & pDevMode.dmYResolution.ToString()) End If If (pDevMode.dmFields And DevModeFields.TTOption) <> 0 Then ListBox3.Items.Add(vbTab & "dmTTOption=" & pDevMode.dmTTOption.ToString()) End If If (pDevMode.dmFields And DevModeFields.Collate) <> 0 Then ListBox3.Items.Add(vbTab & "dmCollate=" & pDevMode.dmCollate.ToString()) End If If (pDevMode.dmFields And DevModeFields.FormName) <> 0 Then ListBox3.Items.Add(vbTab & "dmFormName=" & pDevMode.dmFormName) End If If (pDevMode.dmFields And DevModeFields.LogPixels) <> 0 Then ListBox3.Items.Add(vbTab & "dmLogPixels=" & pDevMode.dmLogPixels.ToString()) End If If (pDevMode.dmFields And DevModeFields.BitsPerpel) <> 0 Then ListBox3.Items.Add(vbTab & "dmBitsPerPel=" & pDevMode.dmBitsPerPel.ToString()) End If If (pDevMode.dmFields And DevModeFields.PelsWidth) <> 0 Then ListBox3.Items.Add(vbTab & "dmPelsWidth=" & pDevMode.dmPelsWidth.ToString()) End If If (pDevMode.dmFields And DevModeFields.PelsHeight) <> 0 Then ListBox3.Items.Add(vbTab & "dmPelsHeight=" & pDevMode.dmPelsHeight.ToString()) End If If (pDevMode.dmFields And DevModeFields.DisplayFlags) <> 0 Then ListBox3.Items.Add(vbTab & "dmDisplayFlags=" & pDevMode.dmDisplayFlags.ToString()) End If If (pDevMode.dmFields And DevModeFields.DisplayFrequency) <> 0 Then ListBox3.Items.Add(vbTab & "dmDisplayFrequency=" & pDevMode.dmDisplayFrequency.ToString()) End If If (pDevMode.dmFields And DevModeFields.IcmMethod) <> 0 Then ListBox3.Items.Add(vbTab & "dmICMMethod=" & pDevMode.dmICMMethod.ToString()) End If If (pDevMode.dmFields And DevModeFields.IcmIntent) <> 0 Then ListBox3.Items.Add(vbTab & "dmICMIntent=" & pDevMode.dmICMIntent.ToString()) End If If (pDevMode.dmFields And DevModeFields.MediaType) <> 0 Then ListBox3.Items.Add(vbTab & "dmMediaType=" & pDevMode.dmMediaType.ToString()) End If If (pDevMode.dmFields And DevModeFields.DitherType) <> 0 Then ListBox3.Items.Add(vbTab & "dmDitherType=" & pDevMode.dmDitherType.ToString()) End If If (pDevMode.dmFields And DevModeFields.PanningWidth) <> 0 Then ListBox3.Items.Add(vbTab & "dmPanningWidth=" & pDevMode.dmPanningWidth.ToString()) End If If (pDevMode.dmFields And DevModeFields.PanningHeight) <> 0 Then ListBox3.Items.Add(vbTab & "dmPanningHeight=" & pDevMode.dmPanningHeight.ToString()) End If End If i += 1 info = New DISPLAY_DEVICE() Loop End Sub End Class