Thanks for pointing that thread out, mutant. Im trying to convert the code in that thread from C# to VB.NET. As Ive been learning VB.NET, its been hard not to pick up a little C# along the way, since all the good code samples seem to be in C#, but API calls are a little over my head. So I ran the code through a
C# --> VB.NET parser . Would anyone mind telling me what needs to get fixed here?
[VB]
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Namespace ScreenResolution
_
Public Class Form1
Inherits System.Windows.Forms.Form
_
Public Enum DMDO
[DEFAULT] = 0
D90 = 1
D180 = 2
D270 = 3
End Enum DMDO
<StructLayout(LayoutKind.Sequential, CharSet := CharSet.Auto)> _
Structure DEVMODE
Public DM_PELSWIDTH As Integer = &H80000
Public DM_PELSHEIGHT As Integer = &H100000
Private CCHDEVICENAME As Integer = 32
Private CCHFORMNAME As Integer = 32<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHDEVICENAME)>
Public dmDeviceName As String
Public dmSpecVersion As Short
Public dmDriverVersion As Short
Public dmSize As Short
Public dmDriverExtra As Short
Public dmFields As Integer
Public dmPositionX As Integer
Public dmPositionY As Integer
Public dmDisplayOrientation As DMDO
Public dmDisplayFixedOutput As Integer
Public dmColor As Short
Public dmDuplex As Short
Public dmYResolution As Short
Public dmTTOption As Short
Public dmCollate As Short<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHFORMNAME)>
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
End Structure DEVMODE
--------------------------------\
Shared Declare Auto Function ChangeDisplaySettings Lib "user32.dll" (ByRef<[In]()> lpDevMode As DEVMODE, dwFlags As Integer) As Integer
static extern int ChangeDisplaySettings( DEVMODE lpDevMode, int dwFlags);
should I use this line?
/ <summary>
/ Required designer variable.
/ </summary>
Private components As System.ComponentModel.Container = Nothing
Public Sub New()
Required for Windows Form Designer support
InitializeComponent()
End Sub New
TODO: Add any constructor code after InitializeComponent call
Protected Overrides Sub Dispose(disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub Dispose
ToDo: Error processing original source shown below
-----------^--- Pre-processor directives not translated
/ <summary>
ToDo: Error processing original source shown below
--^--- Unexpected pre-processor directive
/ Required method for Designer support - do not modify
/ the contents of this method with the code editor.
/ </summary>
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.Size = New System.Drawing.Size(300, 300)
Me.Text = "Form1"
End Sub InitializeComponent
ToDo: Error processing original source shown below
-----------^--- Pre-processor directives not translated
ToDo: Error processing original source shown below
--^--- Unexpected pre-processor directive
Shared Sub Main()
Dim r As New Form1()
r.ChangeRes()
Application.Run(New Form1())
End Sub Main
Sub ChangeRes()
Dim t As New Form1()
Dim RetVal As Long = 0
Dim dm As New DEVMODE()
dm.dmSize = CShort(Marshal.SizeOf(GetType(DEVMODE)))
dm.dmPelsWidth = 1024
dm.dmPelsHeight = 768
dm.dmFields = DEVMODE.DM_PELSWIDTH Or DEVMODE.DM_PELSHEIGHT
RetVal = ChangeDisplaySettings(dm, 0)
End Sub ChangeRes
End Class Form1
End Namespace ScreenResolution
[/VB]
My goal here is to make something similar to QuickRes, just a statusbar icon with a popup menu containing the available screen resolutions, color depths, and refresh rates.