VB Code:
  1. ' Original C# Version Copyright 2002 Omniscium, all rights reserved.
  2. ' Converted to VB.NET by Lunatic3
  3. ' Please send your comments :)
  4. Imports System
  5. Imports System.Windows.Forms
  6. Imports System.Drawing
  7. Imports System.Runtime.InteropServices
  8. #Region "DEVMODE_STRUCT"
  9. <StructLayout(LayoutKind.Sequential)> _
  10. Public Structure DEVMODE
  11.     <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
  12.     Public dmDeviceName As String
  13.     Public dmSpecVersion As Short
  14.     Public dmDriverVersion As Short
  15.     Public dmSize As Short
  16.     Public dmDriverExtra As Short
  17.     Public dmFields As Integer
  18.  
  19.     Public dmOrientation As Short
  20.     Public dmPaperSize As Short
  21.     Public dmPaperLength As Short
  22.     Public dmPaperWidth As Short
  23.  
  24.     Public dmScale As Short
  25.     Public dmCopies As Short
  26.     Public dmDefaultSource As Short
  27.     Public dmPrintQuality As Short
  28.     Public dmColor As Short
  29.     Public dmDuplex As Short
  30.     Public dmYResolution As Short
  31.     Public dmTTOption As Short
  32.     Public dmCollate As Short
  33.     <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
  34.     Public dmFormName As String ',
  35.     Public dmLogPixels As Short
  36.     Public dmBitsPerPel As Short
  37.     Public dmPelsWidth As Integer
  38.     Public dmPelsHeight As Integer
  39.  
  40.     Public dmDisplayFlags As Integer
  41.     Public dmDisplayFrequency As Integer
  42.  
  43.     Public dmICMMethod As Integer
  44.     Public dmICMIntent As Integer
  45.     Public dmMediaType As Integer
  46.     Public dmDitherType As Integer
  47.     Public dmReserved1 As Integer
  48.     Public dmReserved2 As Integer
  49.  
  50.     Public dmPanningWidth As Integer
  51.     Public dmPanningHeight As Integer
  52. End Structure
  53.  
  54. #End Region
  55.  
  56. #Region "PINVOKEDEF"
  57. Class User32
  58.  
  59.     Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal deviceName As String, ByVal modeNum As Integer, ByRef devMode As DEVMODE) As Integer
  60.     Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (ByRef devMode As DEVMODE, ByVal flags As Integer) As Integer
  61.     Public Const ENUM_CURRENT_SETTINGS As Integer = -1
  62.     Public Const CDS_UPDATEREGISTRY As Integer = &H1
  63.     Public Const CDS_TEST As Integer = &H2
  64.     Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
  65.     Public Const DISP_CHANGE_RESTART As Integer = 1
  66.     Public Const DISP_CHANGE_FAILED As Integer = -1
  67. End Class
  68. #End Region
  69.  
  70.  
  71.  
  72. Namespace Resolution
  73.     Module Module1
  74.  
  75.        
  76.         Class CResolution
  77.             Shared Sub Main(ByVal args() As String)
  78.                 Dim screen As Screen = screen.PrimaryScreen
  79.                 Console.WriteLine("Screen Width = " & screen.Bounds.Width)
  80.                 Console.WriteLine("Screen Height = " & screen.Bounds.Height)
  81.                 If args.Length <> 2 Then
  82.                     Console.WriteLine("Please pass in the width followed by the height of the resolution you want.")
  83.                     Return
  84.                 End If
  85.                 Dim iWidth As Integer = Int32.Parse(args(0))
  86.                 Dim iHeight As Integer = Int32.Parse(args(1))
  87.                 Dim dm As DEVMODE = New DEVMODE()
  88.                 dm.dmDeviceName = New [String](New Char(32) {})
  89.                 dm.dmFormName = New [String](New Char(32) {})
  90.                 dm.dmSize = CType(Marshal.SizeOf(dm), Short)
  91.                 If 0 <> User32.EnumDisplaySettings(Nothing, User32.ENUM_CURRENT_SETTINGS, dm) Then
  92.                     dm.dmPelsWidth = iWidth
  93.                     dm.dmPelsHeight = iHeight
  94.                     Dim iRet As Integer = User32.ChangeDisplaySettings(dm, User32.CDS_TEST)
  95.                     If iRet = User32.DISP_CHANGE_FAILED Then
  96.                         Console.WriteLine("Change failed")
  97.                     Else
  98.                         iRet = User32.ChangeDisplaySettings(dm, User32.CDS_UPDATEREGISTRY)
  99.                         Select Case iRet
  100.                             Case User32.DISP_CHANGE_SUCCESSFUL
  101.                                 Console.WriteLine("Changed the resolution.")
  102.                             Case User32.DISP_CHANGE_RESTART
  103.                                 Console.WriteLine("You will need to reboot for the change to happen.")
  104.                             Case Else
  105.                                 Console.WriteLine("Failed to change the resolution.")
  106.                         End Select
  107.                     End If
  108.                 End If
  109.             End Sub
  110.         End Class
  111.     End Module
  112. End Namespace