For instance, if the users screen size is 800x600, I want the
resolution to change to 1260x780 when running my program and then
change back to 800x600 when exiting my program.
Thanks,
Darian
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me
Time flies when you don't know what you're doing
"Darian" <darian...@lmicorporation.com> wrote in message
news:fa0307c.04090...@posting.google.com...
http://www.omniscium.com/index.asp?page=DotNetScreenResolution
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me
Time flies when you don't know what you're doing
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:OSv57%23alEH...@TK2MSFTNGP14.phx.gbl...
There is no managed way to do that.
From my FAQ (<URL:http://dotnet.mvps.org/faqs/>):
This solution is based on a sample written by Tom Spink.
Changing the screen resolution makes sense in very few cases, but it is
possible using p/invoke. 'SetResolution' tries to change the screen
resolution to the values passed into the method and returns 'False' if
changing the screen settings fails:
\\\
Imports System.Runtime.InteropServices
.
.
.
Private Declare Auto Function EnumDisplaySettings Lib "user32.dll" ( _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpszDeviceName As String, _
ByVal iModeNum As Int32, _
ByRef lpDevMode As DEVMODE _
) As Boolean
Private Declare Auto Function ChangeDisplaySettings Lib "user32.dll" ( _
ByRef lpDevMode As DEVMODE, _
ByVal dwFlags As Int32 _
) As Int32
Private Const DM_BITSPERPEL As Int32 = &H40000
Private Const DM_PELSWIDTH As Int32 = &H80000
Private Const DM_PELSHEIGHT As Int32 = &H100000
Private Const DISP_CHANGE_SUCCESSFUL As Int32 = 0
<StructLayout(LayoutKind.Sequential)> _
Private Structure POINTL
Public x As Int32
Public y As Int32
End Structure
<StructLayout(LayoutKind.Explicit)> _
Private Structure DEVMODE_union1
' struct {
<FieldOffset(0)> Public dmOrientation As Int16
<FieldOffset(2)> Public dmPaperSize As Int16
<FieldOffset(4)> Public dmPaperLength As Int16
<FieldOffset(6)> Public dmPaperWidth As Int16
' }
<FieldOffset(0)> Public dmPosition As POINTL
End Structure
<StructLayout(LayoutKind.Explicit)> _
Private Structure DEVMODE_union2
<FieldOffset(0)> Public dmDisplayFlags As Int32
<FieldOffset(0)> Public dmNup As Int32
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure DEVMODE
Private Const CCDEVICENAME As Int32 = 32
Private Const CCFORMNAME As Int32 = 32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
Public dmDeviceName As String
Public dmSpecVersion As Int16
Public dmDriverVersion As Int16
Public dmSize As Int16
Public dmDriverExtra As Int16
Public dmFields As Int32
Public u1 As DEVMODE_union1
Public dmScale As Int16
Public dmCopies As Int16
Public dmDefaultSource As Int16
Public dmPrintQuality As Int16
Public dmColor As Int16
Public dmDuplex As Int16
Public dmYResolution As Int16
Public dmTTOption As Int16
Public dmCollate As Int16
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _
Public dmFormName As String
Public dmUnusedPadding As Int16
Public dmBitsPerPel As Int16
Public dmPelsWidth As Int32
Public dmPelsHeight As Int32
Public u2 As DEVMODE_union2
Public dmDisplayFrequency As Int32
Public dmICMMethod As Int32
Public dmICMIntent As Int32
Public dmMediaType As Int32
Public dmDitherType As Int32
Public dmReserved1 As Int32
Public dmReserved2 As Int32
Public dmPanningWidth As Int32
Public dmPanningHeight As Int32
End Structure
Public Function SetResolution( _
ByVal Width As Int32, _
ByVal Height As Int32, _
ByVal BitsPerPixel As Int16 _
) As Boolean
Dim dm As DEVMODE
If Not EnumDisplaySettings(Nothing, 0, dm) Then
Return False
Else
With dm
.dmFields = _
DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
.dmPelsWidth = Width
.dmPelsHeight = Height
.dmBitsPerPel = BitsPerPixel
End With
Return (ChangeDisplaySettings(dm, 0) = DISP_CHANGE_SUCCESSFUL)
End If
End Function
///
Usage:
\\\
Debug.Assert(SetResolution(1024, 768, 32))
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Just my 2 cents.
"Darian" <darian...@lmicorporation.com> wrote in message
news:fa0307c.04090...@posting.google.com...
Thanks again everybody.
Darian
¤ I am wondering how (if it is possible of course) I can change a users
This is a no-no. First there is no guarantee that the user's setup will support the higher
resolution, and second, I don't know many users that would appreciate having their screen resolution
changed on the fly without being offered the option to do so. Any application which did this would
be uninstalled from my machine in a heartbeat.
I would simply check their current screen resolution and display a message which indicates that your
application requires a higher resolution to function properly. Allow them to decide whether to
change the resolution through your application or via the Display Control Panel applet.
Paul ~~~ pcle...@ameritech.net
Microsoft MVP (Visual Basic)