La Web del Programador: Comunidad de Programadores
 
    Pregunta:  34402 - CAMBIO DE RESOLUCION DE PANTALLA EN WINXP
Autor:  Enrique García Polo
Desearía saber como puedo cambiar la resolucion de pantalla en Windows Xp, ya q con la api q usaba para cambiarla en el resto de los windows ya no funciona en Windows Xp, sólo consigo sacar las resoluciones disponibles pero no cambiarla.

Ruego ayuda urgente pues es para un trabajo y me queda poco tiempo,

Muchas Gracias!!!

  Respuesta:  SuNcO
Con este si me funciona :

Requieres :

1 check (nombre = chkBits)
1 command_button (nombre = command1)
2 label (nombres = label1(0) y label1(1))
1 list (nombre = list1)

' Option Explicit

Private Type tResol
Width As Long
Height As Long
Bits As Integer
End Type
Private Disponibles() As tResol

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

Const CCDEVICENAME = 32
Const CCFORMNAME = 32
'Las declaraciones de estas constantes están en: Wingdi.h
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000

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

Dim DevM As DEVMODE

Private Sub Form_Load()
'Mostrar las resoluciones disponibles
Dim a As Boolean
Dim i As Long

With Screen
Label1(0) = "Resolución actual: " & (.Width \ .TwipsPerPixelX) & " x " & _
(.Height \ .TwipsPerPixelY)
End With
i = 0
Do
a = EnumDisplaySettings(0&, i&, DevM)
i = i + 1
If a Then
'Mostrar en el listbox las resoluciones disponibles
List1.AddItem Format$(DevM.dmPelsWidth, " @@@@") & " x " & _
Format$(DevM.dmPelsHeight, "@@@@") & " " & _
Format$(DevM.dmBitsPerPel, "@@") & " bits"
'Guardar esos datos en nuestro array
'de las resoluciones disponibles
ReDim Preserve Disponibles(i - 1)
With Disponibles(i - 1)
.Width = DevM.dmPelsWidth
.Height = DevM.dmPelsHeight
.Bits = DevM.dmBitsPerPel
End With
End If
Loop While a
'Deshabilitar el botón hasta que se seleccione algo
Command1.Enabled = False
End Sub

Private Sub Command1_Click()
'Cambiar a la resolución indicada
Dim i As Long

'índice de la selección en el ListBox
i = List1.ListIndex

'Se le indica los campos a tener en cuenta
'
'Si sólo se quiere cambiar la resolución,
'manteniendo los colores:
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
'Si se quiere cambiar también los colores
If chkBits.Value Then
DevM.dmFields = DevM.dmFields Or DM_BITSPERPEL
'DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
End If

With Disponibles(i)
DevM.dmPelsWidth = .Width
DevM.dmPelsHeight = .Height
DevM.dmBitsPerPel = .Bits
End With

Call ChangeDisplaySettings(DevM, 0)

With Screen
Label1(0) = "Resolución actual: " & (.Width \ .TwipsPerPixelX) & " x " & _
(.Height \ .TwipsPerPixelY)
End With

End Sub

Private Sub List1_Click()
Dim i As Long

i = List1.ListIndex
'Mostrar en el label la resolución seleccionada
Label1(1) = "Cambiar a: " & Disponibles(i).Width & " x " & _
Disponibles(i).Height & " " & _
Disponibles(i).Bits & " bits"
'Ya hay una selección, habilitamos el botón
Command1.Enabled = True
End Sub