Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Public Structure DEVMODE1
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
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 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
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public dmFormName As String
Public dmLogPixels As Short
Public dmBitsPerPel As Short
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
Class User_32
Public Declare Function EnumDisplaySettings Lib "user32.dll" (ByVal deviceName As String, ByVal modeNum As Integer, ByRef devMode As DEVMODE1) As Integer
Public Declare Function ChangeDisplaySettings Lib "user32.dll" (ByRef devMode As DEVMODE1, ByVal flags As Integer) As Integer
Public Const ENUM_CURRENT_SETTINGS As Integer = -1
Public Const CDS_UPDATEREGISTRY As Integer = 1
Public Const CDS_TEST As Integer = 2
Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
Public Const DISP_CHANGE_RESTART As Integer = 1
Public Const DISP_CHANGE_FAILED As Integer = -1
End Class
Namespace Resolution
Public Class CResolution
Public Sub New(ByVal a As Integer, ByVal b As Integer)
MyBase.New()
Dim screen As Screen = screen.PrimaryScreen
Dim iWidth As Integer = a
Dim iHeight As Integer = b
Dim dm As DEVMODE1 = New DEVMODE1
dm.dmDeviceName = New String(New Char((32) - 1) {})
dm.dmFormName = New String(New Char((32) - 1) {})
dm.dmSize = CType(Marshal.SizeOf(dm), Short)
If (0 <> User_32.EnumDisplaySettings(Nothing, User_32.ENUM_CURRENT_SETTINGS, dm)) Then
dm.dmPelsWidth = iWidth
dm.dmPelsHeight = iHeight
Dim iRet As Integer = User_32.ChangeDisplaySettings(dm, User_32.CDS_TEST)
If (iRet = User_32.DISP_CHANGE_FAILED) Then
MsgBox("Unable to process your request")
MsgBox("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButton.OK)
Else
iRet = User_32.ChangeDisplaySettings(dm, User_32.CDS_UPDATEREGISTRY)
Select Case (iRet)
Case User_32.DISP_CHANGE_SUCCESSFUL
Exit Select
Case User_32.DISP_CHANGE_RESTART
MsgBox("Description: You Need To Reboot For The Change To Happen." & vbLf & " If You Feel Any Problem After Rebooting Yo" & _
"ur Machine" & vbLf & "Then Try To Change Resolution In Safe Mode.", "Information", MessageBoxButton.OK)
Exit Select
Case Else
MsgBox("Description: Failed To Change The Resolution.", "Information", MessageBoxButton.OK)
Exit Select
End Select
End If
End If
End Sub
End Class
End Namespace
Tag : .NET, Web (ASP.NET), WebService, VB.NET, C, Windows