Cambiar la resolución y restaurarla cuando vaya a salir de la aplicación

Hola, buenas tardes, necesito una ayuda, como puedo cambiar desde Vb, la resolucion ponerla en 800 x 600 y al salir de la aplicacion, restaurarla a la original.
Muchas Gracias.

1 respuesta

Respuesta
1
Para eso hay que recurrir a la API, copia esto en el procedimiento general del formulario principal:
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
Dim OldX As Long, OldY As Long, nDC As Long
Sub ChangeRes(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_SUCCESSFUL
erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
ScInfo = Y * 2 ^ 16 + X
SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
Case Else
MsgBox "Modo no soportado", vbOKOnly + vbSystemModal, "Error"
End Select
End Sub
Ahora lo utilzas de este modo, puedes colocar el primer codigo el el evento Load del formulario:
Dim nDC As Long
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
ChangeRes 800, 600, GetDeviceCaps(nDC, BITSPIXEL)
'luego colocas este codigo en el evento Unload:
ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
DeleteDC nDC
Asi al ingresar al programa te colocara la ventana en 800X600 y al salir te restaurara a los valores en la que estaba.
Eso es por los drivers de la palca de video, fijate que si cambias de resolucion desde la configuracion de video tambien te hara ese parpadeo, es que la palca de video, sus drivers y windows tienes que cambiar varios parametros, incluso el los monitores al detectar un cambio es la resolucion y freceuncias de muestreo tambien se toma unos segundos en reponerce.
Por que requieres cambiar a esa resolucion, ¿no puedes dejar esa maquina simepre en 800X600?

Añade tu respuesta

Haz clic para o
El autor de la pregunta ya no la sigue por lo que es posible que no reciba tu respuesta.

Más respuestas relacionadas