Access de Xavi

Funciones => API => Mensaje iniciado por: xavi en Mayo 09, 2023, 01:05:37 AM

Título: Obtener resolución de pantalla
Publicado por: xavi en Mayo 09, 2023, 01:05:37 AM
Palabras clave: configuración, resolución, TWIPS, API, GetSystemMetrics
Autor: Jacob Hilderbrand
Extraído de: VBA Express (http://www.vbaexpress.com/kb/getarticle.php?kb_id=32)

Objetivo:
Determinar la resolución de la pantalla y proponer cambio.

En un módulo independiente:

Option Explicit

Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Sub VerifyScreenResolution(Optional Dummy As Integer)
     
    Dim x  As Long
    Dim y  As Long
    Dim MyMessage As String
    Dim MyResponse As VbMsgBoxResult
     
    x = GetSystemMetrics(SM_CXSCREEN)
    y = GetSystemMetrics(SM_CYSCREEN)
    If x = 1024 And y = 768 Then
    Else
        MyMessage = "Your current screen resolution is " & x & " X " & y & vbCrLf & "This program " & _
        "was designed to run with a screen resolution of 1024 X 768 and may not function properly " & _
        "with your current settings." & vbCrLf & "Would you like to change your screen resolution?"
        MyResponse = MsgBox(MyMessage, vbExclamation + vbYesNo, "Screen Resolution")
    End If
    If MyResponse = vbYes Then
        Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3")
    End If
End Sub