Problema configuración monitor

Este código me permite cambiar la configuración del monitor
Option Explicit
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
Dim OldX As Long, OldY As Long, nDC As Long
Sub mCambiarResolucion(X As Long, Y As Long, Bits As Long)
Dim DevM As DEVMODE, Erg As Long, an As Integer
'Get the info into DevM
Erg& = EnumDisplaySettings(0&, 0&, DevM)
'This is what we're going to change
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = X 'ScreenWidth
DevM.dmPelsHeight = Y 'ScreenHeight
DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
'Now change the display and check if possible
Erg& = ChangeDisplaySettings(DevM, CDS_TEST)
'Check if succesfull
Select 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 "La resolución es: " & X & " x " & Y, vbOKOnly + vbSystemModal
Case Else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
End Select
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Command2_Click()
mCambiarResolucion 1024, 768, GetDeviceCaps(nDC, BITSPIXEL)
'delete our device context
DeleteDC nDC
End Sub
Private Sub Command3_Click()
mCambiarResolucion 800, 600, GetDeviceCaps(nDC, BITSPIXEL)
'delete our device context
DeleteDC nDC
End Sub
Private Sub Form_Load()
Dim nDC As Long
'Obtener la resolución de la pantalla
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
'Create a device context, compatible with the screen
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
'Change the screen's resolution
mCambiarResolucion OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
End Sub
El problema que se presenta es que cuando la paso de 800 a 1024 la barra de herramientas no se adapta de manera inmediata al tamaño de la pantalla. Esto es de igual forma para regresarla de 1024 a 800. El usuario lo puede hacer de manera manual pero no quiero eso, quiero que cuando se cambie el tamaño de la configuaración de la pantalla se ajuste de manera automática la barra de herramientas
Saludos
Beregerson
Un beso

1 Respuesta

Respuesta
1
A que barra de herramientas te refieras a la de Windows o a la de tu aplicación
a la de la barra de herramientas de windows.
si quieres mete ése códigio y verás de manera específica a que me refiero. Ya que cuando pasas de 1024 a 800 se pierde la barra de herramientas del monitor.
Saludos
Bere
Un beso
Esta dirección, he probado el código y hace lo que tu dices al pasar de 800 a 1024 pero de 1024 a 800 lo hace bien, ten en cuenta que al querer cambiar la resolución desde código se utiliza Api con lo que de un Sistema Operativo a otro puede variar.
Mira en esta página que hay varios ejemplos:
http://guille.costasol.net/api/resolucionpantalla.htm

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas