changing screen res in VB

Started by
3 comments, last by Tetrix 23 years ago
how do you change the screen res from within A vb program? Nothing is ever easy but everything is possible
Nothing is ever easybut everything is possible:)
Advertisement
I completely ripped this off from www.allapi.net (especially http://www.allapi.net/tips/tip049.php) so all credit goes to them

In a module:
  Declare Function EnumDisplaySettings Lib "user32" _Alias "EnumDisplaySettingsA" _(ByVal lpszDeviceName As Long, _ByVal iModeNum As Long, _lpDevMode As Any) As Boolean Declare Function ChangeDisplaySettingsLib "user32" _Alias "ChangeDisplaySettingsA" _(lpDevMode As Any, ByVal dwFlags As Long) As LongDeclare Function ExitWindowsEx Lib "user32" _(ByVal uFlags As Long, ByVal dwReserved As Long) As Long Public Const EWX_LOGOFF = 0Public Const EWX_SHUTDOWN = 1Public Const EWX_REBOOT = 2Public Const EWX_FORCE = 4Public Const CCDEVICENAME = 32Public Const CCFORMNAME = 32Public Const DM_BITSPERPEL = &H40000Public Const DM_PELSWIDTH = &H80000Public Const DM_PELSHEIGHT = &H100000Public Const CDS_UPDATEREGISTRY = &H1Public Const CDS_TEST = &H4Public Const DISP_CHANGE_SUCCESSFUL = 0Public Const DISP_CHANGE_RESTART = 1 Type DEVMODE	dmDeviceName As String * CCDEVICENAME	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 * CCFORMNAME	dmUnusedPadding As Integer	dmBitsPerPel As Integer	dmPelsWidth As Long	dmPelsHeight As Long	dmDisplayFlags As Long	dmDisplayFrequency As LongEnd Type   


Usage:
  Sub SetResolution(Xres As Integer, Yres As Integer, bpp Ss Integer)Dim DevM As DEVMODE''Get the info into DevMerg& = EnumDisplaySettings(0&, 0&, DevM)''We don''t change the colordepth, because a''rebot will be necessaryDevM.dmFields = DM_PELSWIDTH OrDM_PELSHEIGHT ''Or DM_BITSPERPELDevM.dmPelsWidth = Xres ''ScreenWidthDevM.dmPelsHeight = Yres ''ScreenHeight''DevM.dmBitsPerPel = bpp (could be 8, 16, 32 or even 4)''Now change the display and check if possible erg& = ChangeDisplaySettings(DevM, CDS_TEST)''Check if successfulSelect Case erg&Case DISP_CHANGE_RESTART	an = MsgBox("You''ve to reboot", vbYesNo + vbSystemModal, "Info")	If an = vbYes Then		erg& = ExitWindowsEx(EWX_REBOOT, 0&)	End If	Case DISP_CHANGE_SUCCESSFUL	erg& = ChangeDisplaySettings(DevM,	CDS_UPDATEREGISTRY)	MsgBox "Everything''s ok", vbOKOnly +	vbSystemModal, "It worked!"Case Else	MsgBox "Mode not supported", vbOKOnly +	vbSystemModal, "Error"End Select End Sub  


Don''t blame me if it doesn''t work www.allapi.net is very useful for this kind of thing.

Harry.
Harry.
Just curious, but why would you want to do this?
Network admin has disable the ability to change display setting on the computers at college. Our final year project has been designed for a screen resolution of at least 1080,768(this is the specified resolution given by the compay we are doing the project for). The screen res at college is set to 900,600. This will mean when demostrating our program at college it will look crap.

Nothing is ever easy
but everything is possible
Nothing is ever easybut everything is possible:)
thanks man the code works. You might what too change the 'sS' at the procedure start to 'As'.
Thank man, we will put you on the credits.

Nothing is ever easy
but everything is possible

Edited by - Tetrix on March 28, 2001 5:13:43 AM
Nothing is ever easybut everything is possible:)

This topic is closed to new replies.

Advertisement