home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Starfield_2147143182009.psc / cMonitors.cls < prev    next >
Text File  |  2006-07-14  |  3KB  |  123 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cMonitors"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Private Type POINTAPI
  17.    x As Long
  18.    y As Long
  19. End Type
  20.  
  21. Private Const SM_CXVIRTUALSCREEN = 78
  22. Private Const SM_CYVIRTUALSCREEN = 79
  23. Private Const SM_CMONITORS = 80
  24. Private Const SM_SAMEDISPLAYFORMAT = 81
  25.  
  26. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  27.  
  28. Private Declare Function MonitorFromWindow Lib "user32" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
  29. Private Declare Function MonitorFromPoint Lib "user32" (pt As POINTAPI, ByVal dwFlags As Long) As Long
  30. Private Const MONITOR_DEFAULTTONEAREST = 0
  31.  
  32. Private m_iCount As Long
  33. Private m_cM() As cMonitor
  34.  
  35. Public Property Get AllMonitorsSame() As Long
  36.    AllMonitorsSame = GetSystemMetrics(SM_SAMEDISPLAYFORMAT)
  37. End Property
  38.  
  39. Public Property Get MonitorForPoint(ByVal x As Long, ByVal y As Long) As cMonitor
  40. Dim hMon As Long
  41. Dim tP As POINTAPI
  42.    tP.x = x
  43.    tP.y = y
  44.    hMon = MonitorFromPoint(tP, MONITOR_DEFAULTTONEAREST)
  45.    If Not (hMon = 0) Then
  46.       Dim cM As cMonitor
  47.       Set cM = New cMonitor
  48.       cM.fInit hMon
  49.       Set MonitorForPoint = cM
  50.    End If
  51. End Property
  52.  
  53. Public Property Get MonitorForWindow(ByVal hwnd As Long) As cMonitor
  54. Dim hMon As Long
  55.    hMon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST)
  56.    If Not (hMon = 0) Then
  57.       Dim cM As cMonitor
  58.       Set cM = New cMonitor
  59.       cM.fInit hMon
  60.       Set MonitorForWindow = cM
  61.    End If
  62. End Property
  63.  
  64. Public Property Get VirtualScreenLeft() As Long
  65. Dim lRet As Long
  66. Dim i As Long
  67.    lRet = m_cM(1).Left
  68.    For i = 2 To m_iCount
  69.       If (m_cM(i).Left < lRet) Then
  70.          lRet = m_cM(i).Left
  71.       End If
  72.    Next i
  73.    VirtualScreenLeft = lRet
  74. End Property
  75. Public Property Get VirtualScreenTop() As Long
  76. Dim lRet As Long
  77. Dim i As Long
  78.    lRet = m_cM(1).Top
  79.    For i = 2 To m_iCount
  80.       If (m_cM(i).Top < lRet) Then
  81.          lRet = m_cM(i).Top
  82.       End If
  83.    Next i
  84.    VirtualScreenTop = lRet
  85. End Property
  86. Public Property Get VirtualScreenWidth() As Long
  87.    VirtualScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN)
  88. End Property
  89. Public Property Get VirtualScreenHeight() As Long
  90.    VirtualScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN)
  91. End Property
  92. Public Property Get DisplayMonitorCount() As Long
  93.    DisplayMonitorCount = GetSystemMetrics(SM_CMONITORS)
  94. End Property
  95. Public Property Get MonitorCount() As Long
  96.    MonitorCount = m_iCount
  97. End Property
  98. Public Property Get Monitor(ByVal index As Long) As cMonitor
  99.    Set Monitor = m_cM(index)
  100. End Property
  101.  
  102. Friend Sub fAddMonitor( _
  103.       ByVal hMonitor As Long _
  104.    )
  105.  
  106.    
  107.    m_iCount = m_iCount + 1
  108.    ReDim Preserve m_cM(1 To m_iCount) As cMonitor
  109.    Set m_cM(m_iCount) = New cMonitor
  110.    m_cM(m_iCount).fInit hMonitor
  111.      
  112. End Sub
  113.  
  114. Public Sub Refresh()
  115.    m_iCount = 0
  116.    Erase m_cM
  117.    EnumMonitors Me
  118. End Sub
  119.  
  120. Private Sub Class_Initialize()
  121.    Refresh
  122. End Sub
  123.