RE:resolucion de pantalla windows
Gustavo:
Para saber a resolución te bastará con saber el valor de la propiedad Width del objeto Global Screen y dividirlo por 15 (pixels)
Ejemplo.
Private Sub Form_Load()
MsgBox Screen.Width / 15
End Sub
De acuerdo a ello vos sabrías que resolución tiene tu monitor.
Ahora bien, el cambio de resolución es algo más complicado, y debemos recurrir a las API de Windows. Existen controles que hacen esto, pero esos mismos controles, trabajan si o si con estas API que a continuación te detallo.
crea un archivo txt , pega dentro el siguiente codigo y luego cambiale la extensión txt y ponele frm. Ejecutalo y listo. Espero que te sea util
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4005
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 4005
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CheckBox chkBits
Caption = "Cambiar colores"
Height = 255
Left = 360
TabIndex = 2
Top = 3360
Width = 1935
End
Begin VB.ListBox List1
Height = 2010
Left = 240
TabIndex = 1
Top = 720
Width = 2535
End
Begin VB.CommandButton Command1
Caption = "Cambiar la Resolución"
Height = 495
Left = 3360
TabIndex = 0
Top = 360
Width = 1095
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Index = 1
Left = 240
TabIndex = 4
Top = 2880
Width = 2655
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Index = 0
Left = 240
TabIndex = 3
Top = 240
Width = 2655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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