At the start of the application I need to set the screen to a specific size. How would I do this?
Printable View
At the start of the application I need to set the screen to a specific size. How would I do this?
Try this out:VB Code:
Public Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _ (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean Public Declare Function ChangeDisplaySettings Lib "user32" _ Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long Public Const CCDEVICENAME = 32 Public Const CCFORMNAME = 32 Public Const DM_BITSPERPEL = &H40000 Public Const DM_PELSWIDTH = &H80000 Public Const DM_PELSHEIGHT = &H100000 Public Const CDS_UPDATEREGISTRY = &H1 Public Const CDS_TEST = &H4 Public Const DISP_CHANGE_SUCCESSFUL = 0 Public 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 Long End Type Public Sub ChangeScreenSettings() Dim DevM As DEVMODE Dim Ans As Long Dim erg As Long 'Get the info into DevM erg& = EnumDisplaySettings(0&, 0&, DevM) 'We don't change the colordepth, because a 'rebot will be necessary DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL DevM.dmPelsWidth = 1024 'ScreenWidth DevM.dmPelsHeight = 768 'ScreenHeight DevM.dmBitsPerPel = 32 '(could be 8, 16, 32 or even 4) 'Now change the display and check if possible erg& = ChangeDisplaySettings(DevM, CDS_TEST) 'Check if successful Select Case erg& Case DISP_CHANGE_RESTART Ans = MsgBox("You must reboot for the new resolution to take efect!", vbYesNo + vbSystemModal, "Info") If Ans = vbYes Then erg& = ExitWindowsEx(EWX_REBOOT, 0&) End If Case DISP_CHANGE_SUCCESSFUL erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY) Case Else MsgBox "Your Graphics card must be able to support 1024 x 768 resolution!", vbOKOnly + vbSystemModal, "Error" End Select End Sub
VB Code:
Private Sub Form_Initialize() Form1.Height = 3332 Form1.Width = 9372 End Sub