Attribute VB_Name = "basScreenResolutionAdjust"
'*******************************************************************************
' Project   : Generic
'
' Module    : basScreenResolutionAdjust
' DateTime  : 6/21/2006 09:39
' Author    : David Costelloe (found at http://www.andreavb.com/tip090004.html)
'             Edited by Bill Mosca to include parameters.
' References:
' Index     :
'*******************************************************************************

Option Compare Database
Option Explicit

Public Declare Function GetSystemMetrics Lib "user32.dll" _
    (ByVal nIndex As Long) As Long
Private Declare Function EnumDisplaySettings Lib "user32.dll" _
    Alias "EnumDisplaySettingsA" _
    (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Public Declare Function ChangeDisplaySettings Lib "user32.dll" _
    Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000

Public 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

Public DevChg As DEVMODE
 
Public Sub ChangeRes(iWidth As Single, iHeight As Single)
    Dim a As Boolean
    Dim b&
    Dim i&
    
    i = 0

    Do
        a = EnumDisplaySettings(0&, i&, DevChg)
        i = i + 1
    Loop Until (a = False)

    DevChg.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
    DevChg.dmPelsWidth = iWidth
    DevChg.dmPelsHeight = iHeight
    b = ChangeDisplaySettings(DevChg, 0)

End Sub

Public Sub CheckRes(sglWidth As Single, sglHeight As Single)
'Purpose  : Main proc -  Check Screen Resolution.
'           1024 x 768 is the current standard for WinXP.
    Dim X As Long, Y As Long
    Dim MsgTitle As String
    Dim MsgStyle As Long
    Dim Msg As String
    Dim MsgResponse As Long

    Y = GetSystemMetrics(0)
    X = GetSystemMetrics(1)

    If X < sglHeight And Y < sglWidth Then
        MsgTitle = "Invalid Resolution"
        MsgStyle = vbYesNo + vbCritical
        Msg = "You current video resolution is: " & Y & " X " & X _
            & vbCrLf _
            & "This program requires a resolution " & sglWidth _
            & " x " & sglHeight & " or greater." & vbCrLf & vbCrLf _
            & "Do you wish me to adjust your resolution?"
        MsgResponse = MsgBox(Msg, MsgStyle, MsgTitle)
        If MsgResponse = vbYes Then
            Call ChangeRes(sglWidth, sglHeight)
            End
        End If
    End If
End Sub

