Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Changing Display Settings on the Fly
[ All Languages » VB »  Api]

Total Hit ( 3952)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
'Place this code in a Module:
'Place this code in a Module:

Option Explicit
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As _
    Any, lpString2 As Any) As Long
Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32
Private Type DEVMODE
  dmDeviceName As String * CCHDEVICENAME
  dmSpecVersion As Integer
  dmDriverVersion As Integer
  dmSize As Integer
  dmDriverExtra As Integer
  dmFields As Long
  dmOrientation As Integer
  dmPaperSize As Integer
  dmPaperLength As Integer
  dmPaperWidth As Integer
  dmScale As Integer
  dmCopies As Integer
  dmDefaultSource As Integer
  dmPrintQuality As Integer
  dmColor As Integer
  dmDuplex As Integer
  dmYResolution As Integer
  dmTTOption As Integer
  dmCollate As Integer
  dmFormName As String * CCHFORMNAME
  dmUnusedPadding As Integer
  dmBitsPerPel As Integer
  dmPelsWidth As Long
  dmPelsHeight As Long
  dmDisplayFlags As Long
  dmDisplayFrequency As Long
End Type
Private Declare Function ChangeDisplaySettings Lib "User32" Alias _
    "ChangeDisplaySettingsA" (ByVal lsDevMode As Long, ByVal dwFlags _
    As Long) As Long

'Here is the function that sets the display mode. Width is the
'width of the screen. Height is the height of the screen. Color
'is the number of bits per pixel. Set the color value to -1 if
'you only want to change the screen Resolution. This function will
'Return 0 if successful!
Public Function SetDisplayMode(Width As Integer, Height As Integer, _
Color As Integer) As Long

  Const DM_PELSWIDTH = &H80000
  Const DM_PELSHEIGHT = &H100000
  Const DM_BITSPERPEL = &H40000
  Dim NewDevMode As DEVMODE
  Dim pDevMode As Long
  With NewDevMode
    .dmSize = 122
    If Color = -1 Then
      .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
    Else
      .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    End If
    .dmPelsWidth = Width
    .dmPelsHeight = Height
    If Color <> -1 Then
      .dmBitsPerPel = Color
    End If
  End With
  pDevMode = lstrcpy(NewDevMode, NewDevMode)
  SetDisplayMode = ChangeDisplaySettings(pDevMode, 0)
End Function

'Now, to change the Settings, use the following code. The first Argument is the Horizontal 'Width (640) of the screen. The second is the Verticle Height (480) of the screen, and the 'third is the color depth (24 bit).

i = SetDisplayMode(640, 480, 24)


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.