VB Dual screen

vb6 India
  • 7 years ago
    I need to know about how to manage dual screen in vb6

    and how to control secondary monitory from vb

    how to make powerpoint animations in vb ?

    if you know answer of any question ? responce this..........







  • 7 years ago

    Retrieving information about your dual monitor setup can be done with the code below.

     

    Attribute VB_Name = "MonitorInfo"
    Option Explicit

    Public Declare Function LoadLibraryEx Lib "kernel32.dll" Alias "LoadLibraryExA" (ByVal lpFileName As String, ByVal hFile As Long, ByVal dwFlags As Long) As Long
    Public Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Public Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    Public Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Boolean
    Public Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Boolean
    Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFOEX) As Boolean

    Public Const CCHDEVICENAME = 32
    Public Const MONITORINFOF_PRIMARY = &H1

    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type

    Public Type MONITORINFOEX
        cbSize As Long
        rcMonitor As RECT
        rcWork As RECT
        dwFlags As Long
        szDevice As String * CCHDEVICENAME
    End Type

    Dim MonitorId() As String

    Public Sub Test()
    ' At the bottom I have pasted the results on my system.
    Dim i As Integer
        Debug.Print "Number of monitors in this system : " & GetMonitorId
        Debug.Print
        For i = 1 To UBound(MonitorId)
            PrintMonitorInfo (MonitorId(i))
        Next i
    End Sub

    Public Function GetMonitorId()
        ReDim MonitorId(0)
        ' Of course dual screen systems are not available on all Win versions.
        If FunctionExist("user32.dll", "EnumDisplayMonitors") = True Then
            If EnumDisplayMonitors(&H0, ByVal &H0, AddressOf MonitorEnumProc, &H0) = False Then
                Failed "EnumDisplayMonitors"
            End If
        End If
        GetMonitorId = UBound(MonitorId)
    End Function


    Private Sub PrintMonitorInfo(ForMonitorID As String)
    Dim MONITORINFOEX As MONITORINFOEX
        MONITORINFOEX.cbSize = Len(MONITORINFOEX)
        If GetMonitorInfo(CLng(ForMonitorID), MONITORINFOEX) = False Then Failed "GetMonitorInfo"
        With MONITORINFOEX
            Debug.Print "Monitor info for device number : " & ForMonitorID
            Debug.Print "---------------------------------------------------"
            Debug.Print "Device Name : " & .szDevice
            If .dwFlags And MONITORINFOF_PRIMARY Then Debug.Print "Primary Display = True" Else Debug.Print "Primary Display = False"
            With .rcMonitor
                Debug.Print "Monitor Left : " & .Left
                Debug.Print "Monitor Top : " & .Top
                Debug.Print "Monitor Right : " & .Right
                Debug.Print "Monitor Bottom : " & .Bottom
            End With
            With .rcWork
                Debug.Print "Work area Left : " & .Left
                Debug.Print "Work area Top : " & .Top
                Debug.Print "Work area Right : " & .Right
                Debug.Print "Work area Bottom : " & .Bottom
            End With
        End With
        Debug.Print
        Debug.Print
    End Sub


    Public Function FunctionExist(ByVal strModule As String, ByVal strFunction As String) As Boolean
    Dim hHandle As Long
        hHandle = GetModuleHandle(strModule)
        If hHandle = &H0 Then
            Failed "GetModuleHandle"
            hHandle = LoadLibraryEx(strModule, &H0, &H0): If hHandle = &H0 Then Failed "LoadLibrary"
            If GetProcAddress(hHandle, strFunction) = &H0 Then
                Failed "GetProcAddress"
            Else
                FunctionExist = True
            End If
            If FreeLibrary(hHandle) = False Then Failed "FreeLibrary"
        Else
            If GetProcAddress(hHandle, strFunction) = &H0 Then
                Failed "GetProcAddress"
            Else
                FunctionExist = True
            End If
        End If
    End Function


    Public Sub Failed(ByVal strFunction As String)
        If errMsg = True Then
            If Err.LastDllError = 0 Then
                MessageBoxEx &H0, strFunction & Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & "Failed", "Error", MB_OK Or MB_ICONWARNING Or MB_SETFOREGROUND, 0
            Else
                Errors Err.LastDllError, strFunction
            End If
        End If
    End Sub


    Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, ByRef lprcMonitor As RECT, ByVal dwData As Long) As Boolean
    Dim ub As Integer
        ub = 0
        On Error Resume Next
        ub = UBound(MonitorId)
        On Error GoTo 0
        ReDim Preserve MonitorId(ub + 1)
        MonitorId(UBound(MonitorId)) = CStr(hMonitor)
        MonitorEnumProc = 1
    End Function

     

    ' ---------------------------------------------------
    ' Below I have pasted the results of the test
    ' subroutine on my system.
    ' ---------------------------------------------------

     

    ' Number of monitors in this system : 2

    ' Monitor info for device number : 65539
    ' ---------------------------------------------------
    ' Device Name : \\.\DISPLAY1
    ' Primary Display = False
    ' Monitor Left : 1280
    ' Monitor Top : 0
    ' Monitor Right : 2560
    ' Monitor Bottom : 1024
    ' Work area Left : 1280
    ' Work area Top : 0
    ' Work area Right : 2560
    ' Work area Bottom : 1024


    ' Monitor info for device number : 65537
    ' ---------------------------------------------------
    ' Device Name : \\.\DISPLAY2
    ' Primary Display = True
    ' Monitor Left : 0
    ' Monitor Top : 0
    ' Monitor Right : 1280
    ' Monitor Bottom : 1024
    ' Work area Left : 0
    ' Work area Top : 0
    ' Work area Right : 1280
    ' Work area Bottom : 996


     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare