How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?
if possible can i change it back to what it was before the program was opened when it is exited?
Printable View
How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?
if possible can i change it back to what it was before the program was opened when it is exited?
Welcome on the forumsQuote:
Originally Posted by dannyg
Look at my sign resoulation free control :wave:
AllAPI has this example:
http://www.allapi.net/apilist/Change...ettings.shtml#
Click the "Change Resolution" link under Examples.
chem
Form
VB Code:
Option Explicit Private Sub Form_Load() ResizeDisplay True, 1024, 768 End Sub Private Sub Form_Unload(Cancel As Integer) ResizeDisplay (False) End Sub
Module
VB Code:
Option Explicit Const WM_DISPLAYCHANGE = &H7E Const HWND_BROADCAST = &HFFFF& Const EWX_LOGOFF = 0 Const EWX_SHUTDOWN = 1 Const EWX_REBOOT = 2 Const EWX_FORCE = 4 Const CCDEVICENAME = 32 Const CCFORMNAME = 32 Const DM_BITSPERPEL = &H40000 Const DM_PELSWIDTH = &H80000 Const DM_PELSHEIGHT = &H100000 Const CDS_UPDATEREGISTRY = &H1 Const CDS_TEST = &H4 Const DISP_CHANGE_SUCCESSFUL = 0 Const DISP_CHANGE_RESTART = 1 Const BITSPIXEL = 12 Private 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 Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _ (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _ (lpDevMode As Any, ByVal dwFlags As Long) As Long Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, _ ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public OldX As Long Public OldY As Long Public nDC As Long Private Sub ChangeResolution(x As Long, y As Long, Bits As Long) Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult erg = EnumDisplaySettings(0&, 0&, DevM) DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL DevM.dmPelsWidth = x DevM.dmPelsHeight = y DevM.dmBitsPerPel = Bits erg = ChangeDisplaySettings(DevM, CDS_TEST) Select Case erg& Case DISP_CHANGE_RESTART an = MsgBox("You need to restart your computer for new settings to take effect.", vbYesNo + vbSystemModal, "Info") If an = vbYes Then erg& = ExitWindowsEx(EWX_REBOOT, 0&) End If Case DISP_CHANGE_SUCCESSFUL erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY) ScInfo = y * 2 ^ 16 + x SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo 'MsgBox "Resolution has been changed...", vbOKOnly + vbExclamation, "Resolution Change" Case Else MsgBox "Display setting is not supported", vbOKOnly + vbCritical, "Error" End Select End Sub Public Sub ResizeDisplay(ByVal ENABLED As Boolean, Optional ByVal x As Long, Optional ByVal y As Long) If ENABLED And Not IsMissing(x) And Not IsMissing(y) Then If x And y > 0 Then OldX = Screen.Width / Screen.TwipsPerPixelX OldY = Screen.Height / Screen.TwipsPerPixelY nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&) ChangeResolution x, y, GetDeviceCaps(nDC, BITSPIXEL) End If Else If OldX And OldY > 0 Then ChangeResolution OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL) DeleteDC nDC End If End If End Sub
It says display setting not supported when form closes :\
yeah sorry .. edited above code.
Check the code again :wave:Quote:
Originally Posted by dannyg
works .. i had an extra condition in the main sub i didnt need ..Quote:
Originally Posted by shakti5385
check now ..
got it working now thnx :)
no prob .. had the code laying around in an old form ..
just made the new sub and put it in a module for easier use. .
good code by you :wave: boomQuote:
Originally Posted by rory
Sorry to bump such and Old thread but its better then starting a new one.
I using this code.. it "works" fine BUT after I do this:
ResizeDisplay True, 1024, 768
it looks the right size but it sets my Screen.Width to 11520 and my Screen.Height to 11520.
These numbers shouldn't be the same, the width should be like 15360 or something.
Could you tell me what i'm doing wrong or why its doing this?
I copied the Code exactly.
Please Help
using VB6.0 on WinXP SP2.0