screen resolution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ZaGras

    screen resolution

    when my vb program run on another computer instead of my computer, the
    user interface is biggger..this is because of the screen resolution...
    anyone know how to solve pls?
  • edoepke

    #2
    Re: screen resolution

    One way is to check the users screen resolution with the procedure below. If the screen resolution is incorrect you can send the user a message or exit the application.

    Public Function CheckRez(pixelW idth As Long, pixelHeight As Long) As Boolean
    Dim lngTwipsX As Long
    Dim lngTwipsY As Long

    ' convert pixels to twips
    lngTwipsX = pixelWidth * 15
    lngTwipsY = pixelHeight * 15

    ' check against current settings
    If lngTwipsX <> Screen.Width Then
    CheckRez = False
    Else
    If lngTwipsY <> Screen.Height Then
    CheckRez = False
    Else
    CheckRez = True
    End If
    End If
    End Function

    Private Sub Form_Load()
    If CheckRez(800, 600) = False Then
    MsgBox "Incorrect screen size!"
    Else
    MsgBox "Screen Resolution Matches!"
    End If
    End Sub

    Another way is to force a screen resolution change usin API. (Not that adviseable unless you really know what you're doing) To do this you first must add a basic module to your project (if you don't already have one). Place the following declarations into your module:

    Declare Function EnumDisplaySett ings Lib "user32" Alias "EnumDisplaySet tingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean

    Declare Function ChangeDisplaySe ttings Lib "user32" Alias "ChangeDisplayS ettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

    Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

    Public Const EWX_LOGOFF = 0
    Public Const EWX_SHUTDOWN = 1
    Public Const EWX_REBOOT = 2
    Public Const EWX_FORCE = 4

    Public Const CCDEVICENAME = 32
    Public Const CCFORMNAME = 32
    Public Const DM_BITSPERPEL = &H40000
    Public Const DM_PELSWIDTH = &H80000
    Public Const DM_PELSHEIGHT = &H100000
    Public Const CDS_UPDATEREGIS TRY = &H1
    Public Const CDS_TEST = &H4
    Public Const DISP_CHANGE_SUC CESSFUL = 0
    Public Const DISP_CHANGE_RES TART = 1

    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

    dmDisplayFreque ncy As Long
    End Type

    NOW PLACE THE FOLLOWING CODE IN THE DECLARATIONS SECTION OF YOUR FORM:

    Private Sub Form_Activate()
    Dim DevM As DEVMODE
    Dim erg&
    Dim an

    'Get the info into DevM
    erg& = EnumDisplaySett ings(0&, 0&, DevM)

    'We don't change the colordepth, because a reboot will be necessary

    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
    DevM.dmPelsWidt h = 1024 'ScreenWidth - could also be 800, etc
    DevM.dmPelsHeig ht = 768 'ScreenHeight - could also be 600, etc

    'DevM.dmBitsPer Pel = 32 (could be 8, 16, 32 or even 4)

    'Now change the display and check if possible
    erg& = ChangeDisplaySe ttings(DevM, CDS_TEST)

    'Check if succesfull
    Select Case erg&

    Case DISP_CHANGE_RES TART
    an = MsgBox("You need to reboot", vbYesNo + vbSystemModal, "Info")
    If an = vbYes Then
    erg& = ExitWindowsEx(E WX_REBOOT, 0&)
    End If
    Case DISP_CHANGE_SUC CESSFUL
    erg& = ChangeDisplaySe ttings(DevM, CDS_UPDATEREGIS TRY)
    MsgBox "Everything 's ok", vbOKOnly + vbSystemModal, "It worked!"

    Case Else
    MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
    End Select
    End Sub

    Hope this helps.


    "ZaGras" <zagras812@hotm ail.com> wrote in message news:ef27302c.0 311080908.1abc8 6d9@posting.goo gle.com...[color=blue]
    > when my vb program run on another computer instead of my computer, the
    > user interface is biggger..this is because of the screen resolution...
    > anyone know how to solve pls?[/color]

    Comment

    Working...