home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / RM_Secure20301611112006.psc / cFindWindow.cls < prev    next >
Text File  |  2006-11-11  |  4KB  |  128 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 = "cFindWIndow"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '============================================================================================================
  15. '   Pulled from VbAccelerator
  16. '   http://www.vbaccelerator.com/home/vb/code/Libraries/Windows/Enumerating_Windows/article.asp
  17. '============================================================================================================
  18.  
  19. Option Explicit
  20.  
  21. Implements IEnumWindowsSink
  22.  
  23. Private m_sTitleToFInd As String
  24. Private m_sClassToFind As String
  25. Private m_lHwndFound As Long
  26.  
  27. Public Property Let TitleToFind(ByVal sTitle As String)
  28.     m_sTitleToFInd = sTitle
  29.     m_lHwndFound = 0
  30. End Property
  31. Public Property Get TitleToFind() As String
  32.     TitleToFind = m_sTitleToFInd
  33. End Property
  34. Public Property Let ClassToFind(ByVal sClass As String)
  35.     m_sClassToFind = sClass
  36.     m_lHwndFound = 0
  37. End Property
  38. Public Property Get ClassToFind() As String
  39.     ClassToFind = m_sClassToFind
  40. End Property
  41. Public Property Get hWndFound() As Long
  42.     hWndFound = m_lHwndFound
  43. End Property
  44. Private Function pbTitleFound(ByVal lHwnd As Long) As Boolean
  45. Dim sWinTitle As String
  46.     sWinTitle = WindowTitle(lHwnd)
  47.     If (pbTextMatch(m_sTitleToFInd, sWinTitle)) Then
  48.         pbTitleFound = True
  49.     End If
  50. End Function
  51. Private Function pbTextMatch(ByVal sMatch As String, ByVal sText As String) As Boolean
  52. Dim lLen As Long
  53.     ' sMatch is the text to match, sText is the Window title:
  54.     If Left$(sMatch, 1) = "%" And Right$(sMatch, 1) = "%" Then
  55.         Debug.Print sText, sMatch
  56.         If (Len(sMatch) <= 2) Then
  57.             pbTextMatch = True
  58.         Else
  59.             If (InStr(sText, Mid$(sMatch, 2, Len(sMatch) - 2)) <> 0) Then
  60.                 pbTextMatch = True
  61.             End If
  62.         End If
  63.     ElseIf Left$(sMatch, 1) = "%" Then
  64.         If (Len(sMatch) <= 0) Then
  65.             pbTextMatch = True
  66.         Else
  67.             lLen = Len(sMatch) - 1
  68.             If (lLen <= Len(sText)) Then
  69.                 If InStr(sText, Mid$(sMatch, 2)) <> 0 Then
  70.                     pbTextMatch = True
  71.                 End If
  72.             End If
  73.         End If
  74.     ElseIf Right$(sMatch, 1) = "%" Then
  75.         lLen = Len(sMatch) - 1
  76.         If (Len(sMatch) <= 0) Then
  77.             pbTextMatch = True
  78.         Else
  79.             If (lLen <= Len(sText)) Then
  80.                 If InStr(sText, Left$(sMatch, lLen)) <> 0 Then
  81.                     pbTextMatch = True
  82.                 End If
  83.             End If
  84.         End If
  85.     Else
  86.         If (sMatch = sText) Then
  87.             pbTextMatch = True
  88.         End If
  89.     End If
  90. End Function
  91. Public Function FindWindow() As Boolean
  92.     m_lHwndFound = 0
  93.     EnumerateWindows Me
  94.     FindWindow = (m_lHwndFound <> 0)
  95. End Function
  96. Private Function pbClassFound(ByVal lHwnd As Long) As Boolean
  97. Dim sClass As String
  98.     sClass = ClassName(lHwnd)
  99.     If (pbTextMatch(m_sClassToFind, sClass)) Then
  100.         pbClassFound = True
  101.     End If
  102. End Function
  103.  
  104. Private Sub IEnumWindowsSink_EnumWindow(ByVal hwnd As Long, bStop As Boolean)
  105. Dim bFound As Boolean
  106. Dim bTitleCheckFalse As Boolean
  107.     If (IsWindowVisible(hwnd)) Then
  108.         If Len(m_sTitleToFInd) > 0 Then
  109.             bFound = pbTitleFound(hwnd)
  110.             If Not (bFound) Then
  111.                 bTitleCheckFalse = True
  112.             End If
  113.         End If
  114.         If Len(m_sClassToFind) > 0 And Not (bTitleCheckFalse) Then
  115.             bFound = pbClassFound(hwnd)
  116.         End If
  117.     End If
  118.     If (bFound) Then
  119.         m_lHwndFound = hwnd
  120.     End If
  121.     bStop = bFound
  122.  
  123. End Sub
  124.  
  125. Private Property Get IEnumWindowsSink_Identifier() As Long
  126.     IEnumWindowsSink_Identifier = Rnd * 1000000000
  127. End Property
  128.