home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / window2a / clswinvi.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-09-06  |  19.1 KB  |  531 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 = "clsWinView"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  17. Option Explicit
  18.  
  19. ' Name:     Windows Information Viewer
  20. ' Author:   Chong Long Choo
  21. ' Date:     06 September 1999
  22.  
  23. ' API type definitions
  24.  
  25. Private Type POINTAPI
  26.     x As Long
  27.     y As Long
  28. End Type
  29.  
  30. Private Type RECT
  31.     Left As Long
  32.     Top As Long
  33.     Right As Long
  34.     Bottom As Long
  35. End Type
  36.  
  37. ' Window field offsets for GetWindowLong() and GetWindowWord()
  38.  
  39. Const GWL_WNDPROC = (-4)
  40. Const GWL_HINSTANCE = (-6)
  41. Const GWL_HWNDPARENT = (-8)
  42. Const GWL_STYLE = (-16)
  43. Const GWL_EXSTYLE = (-20)
  44. Const GWL_USERDATA = (-21)
  45. Const GWL_ID = (-12)
  46.  
  47. ' Class field offsets for GetClassLong() and GetClassWord()
  48.  
  49. Const GCL_MENUNAME = (-8)
  50. Const GCL_HBRBACKGROUND = (-10)
  51. Const GCL_HCURSOR = (-12)
  52. Const GCL_HICON = (-14)
  53. Const GCL_HMODULE = (-16)
  54. Const GCL_CBWNDEXTRA = (-18)
  55. Const GCL_CBCLSEXTRA = (-20)
  56. Const GCL_WNDPROC = (-24)
  57. Const GCL_STYLE = (-26)
  58. Const GCW_ATOM = (-32)
  59.  
  60. ' Window Styles
  61.  
  62. Const WS_OVERLAPPED = &H0&
  63. Const WS_POPUP = &H80000000
  64. Const WS_CHILD = &H40000000
  65. Const WS_MINIMIZE = &H20000000
  66. Const WS_VISIBLE = &H10000000
  67. Const WS_DISABLED = &H8000000
  68. Const WS_CLIPSIBLINGS = &H4000000
  69. Const WS_CLIPCHILDREN = &H2000000
  70. Const WS_MAXIMIZE = &H1000000
  71. Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
  72. Const WS_BORDER = &H800000
  73. Const WS_DLGFRAME = &H400000
  74. Const WS_VSCROLL = &H200000
  75. Const WS_HSCROLL = &H100000
  76. Const WS_SYSMENU = &H80000
  77. Const WS_THICKFRAME = &H40000
  78. Const WS_GROUP = &H20000
  79. Const WS_TABSTOP = &H10000
  80. Const WS_MINIMIZEBOX = &H20000
  81. Const WS_MAXIMIZEBOX = &H10000
  82.  
  83. ' Thank to Steve McMahon because provide me all the
  84. ' constant of Extended Window Styles.
  85. ' Extended Window Styles
  86. ' NT3.5x
  87. Private Const WS_EX_DLGMODALFRAME = &H1&
  88. Private Const WS_EX_NOPARENTNOTIFY = &H4&
  89. Private Const WS_EX_TOPMOST = &H8&
  90. Private Const WS_EX_ACCEPTFILES = &H10&
  91. Private Const WS_EX_TRANSPARENT = &H20&
  92.  
  93. ' Win9x/NT4
  94. Private Const WS_EX_MDICHILD = &H40&
  95. Private Const WS_EX_TOOLWINDOW = &H80&
  96. Private Const WS_EX_WINDOWEDGE = &H100&
  97. Private Const WS_EX_CLIENTEDGE = &H200&
  98. Private Const WS_EX_CONTEXTHELP = &H400&
  99.  
  100. Private Const WS_EX_RIGHT = &H1000&
  101. Private Const WS_EX_LEFT = &H0&
  102. Private Const WS_EX_RTLREADING = &H2000&
  103. Private Const WS_EX_LTRREADING = &H0&
  104. Private Const WS_EX_LEFTSCROLLBAR = &H4000&
  105. Private Const WS_EX_RIGHTSCROLLBAR = &H0&
  106.  
  107. Private Const WS_EX_CONTROLPARENT = &H10000
  108. Private Const WS_EX_STATICEDGE = &H20000
  109. Private Const WS_EX_APPWINDOW = &H40000
  110.  
  111. Private Const WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE Or WS_EX_CLIENTEDGE)
  112. Private Const WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST)
  113.  
  114. ' Win2000
  115. Private Const WS_EX_LAYERED = &H80000
  116. Private Const WS_EX_NOINHERITLAYOUT = &H100000      '// Disable inheritence of mirroring by children
  117. Private Const WS_EX_LAYOUTRTL = &H400000            '// Right to left mirroring
  118. Private Const WS_EX_NOACTIVATE = &H8000000
  119.  
  120. ' Class styles
  121. Const CS_VREDRAW = &H1
  122. Const CS_HREDRAW = &H2
  123. Const CS_KEYCVTWINDOW = &H4
  124. Const CS_DBLCLKS = &H8
  125. Const CS_OWNDC = &H20
  126. Const CS_CLASSDC = &H40
  127. Const CS_PARENTDC = &H80
  128. Const CS_NOKEYCVT = &H100
  129. Const CS_NOCLOSE = &H200
  130. Const CS_SAVEBITS = &H800
  131. Const CS_BYTEALIGNCLIENT = &H1000
  132. Const CS_BYTEALIGNWINDOW = &H2000
  133. Const CS_PUBLICCLASS = &H4000
  134.  
  135. Const GW_HWNDNEXT = 2
  136. Const GW_OWNER = 4
  137. Const GW_CHILD = 5
  138. Const GW_MAX = 5
  139.  
  140. Const WM_USER = &H400
  141.  
  142. ' API Functions
  143. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
  144. Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
  145. Private Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
  146. Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
  147. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  148. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  149. Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
  150. Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  151. Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam&) As Long
  152. Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
  153. Private Declare Function GetCapture Lib "user32" () As Long
  154. Private Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  155. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  156. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  157. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  158. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  159. Private Declare Function ReleaseCapture Lib "user32" () As Long
  160. Private Declare Function SendMessageLongByRef Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, lParam As Long) As Long
  161. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
  162. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
  163. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  164. Private Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  165. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  166. Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  167. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  168. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
  169. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  170.  
  171. ' Build a list of all top level windows.
  172. Public Sub ListTopLevelWindow()
  173.     Dim hwnd As Long
  174.     Dim res As Long
  175.     Set objListTop = New clsWinView
  176.     res = EnumWindows(AddressOf CallBack_EnumWindows, 0&)
  177.     Set objListTop = Nothing
  178. End Sub
  179.  
  180. '   Show the position of the selected window
  181. Public Sub GetPosition(hwnd As Long, WinPosition As clsWinPosition, Optional strWindow As String)
  182.     Dim WindowRect As RECT
  183.     Dim useHwnd As Long
  184.     Dim objTmpWinPos As clsWinPosition
  185.     Set objTmpWinPos = New clsWinPosition
  186.     If hwnd Then
  187.         useHwnd = hwnd
  188.     Else
  189.         useHwnd = GetHwndFromWord(strWindow)
  190.     End If
  191.     ' Get the rectangle describing the window
  192.     GetWindowRect useHwnd, WindowRect
  193.     With objTmpWinPos
  194.         .Is_Iconic = (IsIconic(useHwnd))
  195.         .Is_Zoomed = (IsZoomed(useHwnd))
  196.         .Is_Enabled = (IsWindowEnabled(useHwnd))
  197.         .Is_Visible = (IsWindowVisible(useHwnd))
  198.         .Left = WindowRect.Left
  199.         .Top = WindowRect.Top
  200.         .Right = WindowRect.Right
  201.         .Bottom = WindowRect.Bottom
  202.     End With
  203.     Set WinPosition = objTmpWinPos
  204. End Sub
  205.  
  206. '   Show the size of the selected window
  207. Public Sub GetSize(hwnd As Long, WinSize As clsWinSize, Optional strWindow As String)
  208.     Dim WindowClientRect As RECT
  209.     Dim useHwnd As Long
  210.     Dim objTmpWinSize As clsWinSize
  211.     Set objTmpWinSize = New clsWinSize
  212.     If hwnd Then
  213.         useHwnd& = hwnd
  214.     Else
  215.         useHwnd& = GetHwndFromWord(strWindow)
  216.     End If
  217.     ' Get the rectangle describing the window
  218.     GetClientRect useHwnd, WindowClientRect
  219.     objTmpWinSize.Horiz_Pixels = WindowClientRect.Right
  220.     objTmpWinSize.Vert_Pixels = WindowClientRect.Bottom
  221.     Set WinSize = objTmpWinSize
  222. End Sub
  223.  
  224. ' Show class styles for the selected window
  225. Public Sub GetClassInfo(hwnd As Long, ClassInfo As clsClassInfo, Optional strWindow As String)
  226.     Dim clsextra As Long, wndextra As Long
  227.     Dim style As Long
  228.     Dim useHwnd As Long
  229.     Dim objTmpClassInfo As clsClassInfo
  230.     Set objTmpClassInfo = New clsClassInfo
  231.     If hwnd Then
  232.         useHwnd = hwnd
  233.     Else
  234.         useHwnd = GetHwndFromWord(strWindow)
  235.     End If
  236.     ' Get the class info
  237.     ' These all used to be GetClassWord and GCW_ constants
  238.     clsextra = GetClassLong(useHwnd, GCL_CBCLSEXTRA)
  239.     wndextra = GetClassLong(useHwnd, GCL_CBWNDEXTRA)
  240.     style = GetClassLong(useHwnd, GCL_STYLE)
  241.     With objTmpClassInfo
  242.         .Class_Extra = clsextra
  243.         .Word_Extra = wndextra
  244.         .CS_BYTEALIGNCLIENT = (style And CS_BYTEALIGNCLIENT)
  245.         .CS_BYTEALIGNWINDOW = style And CS_BYTEALIGNWINDOW
  246.         .CS_CLASSDC = (style And CS_CLASSDC)
  247.         .CS_DBLCLKS = (style And CS_DBLCLKS)
  248.         .CS_PUBLICCLASS = (style And CS_PUBLICCLASS)
  249.         .CS_HREDRAW = (style And CS_HREDRAW)
  250.         .CS_NOCLOSE = (style And CS_NOCLOSE)
  251.         .CS_OWNDC = (style And CS_OWNDC)
  252.         .CS_PARENTDC = (style And CS_PARENTDC)
  253.         .CS_SAVEBITS = (style And CS_SAVEBITS)
  254.         .CS_VREDRAW = (style And CS_VREDRAW)
  255.     End With
  256.     Set ClassInfo = objTmpClassInfo
  257. End Sub
  258.  
  259. ' Show window extra styles for the selected window
  260. Public Sub GetWinExStyle(hwnd As Long, WinExStyle As clsWinExStyle, Optional strWindow As String)
  261.     Dim style As Long
  262.     Dim useHwnd As Long
  263.     Dim objTmpWinExStyle As clsWinExStyle
  264.     Set objTmpWinExStyle = New clsWinExStyle
  265.     If hwnd Then
  266.         useHwnd = hwnd
  267.     Else
  268.         useHwnd = GetHwndFromWord(strWindow)
  269.     End If
  270.     ' Get the class info
  271.     style& = GetWindowLong&(useHwnd&, GWL_EXSTYLE)
  272.     With objTmpWinExStyle
  273.         .WS_EX_DLGMODALFRAME = (style And WS_EX_DLGMODALFRAME)
  274.         .WS_EX_NOPARENTNOTIFY = (style And WS_EX_NOPARENTNOTIFY)
  275.         .WS_EX_TOPMOST = (style And WS_EX_TOPMOST)
  276.         .WS_EX_ACCEPTFILES = (style And WS_EX_ACCEPTFILES)
  277.         .WS_EX_TRANSPARENT = (style And WS_EX_TRANSPARENT)
  278.         .WS_EX_MDICHILD = (style And WS_EX_MDICHILD)
  279.         .WS_EX_TOOLWINDOW = (style And WS_EX_TOOLWINDOW)
  280.         .WS_EX_WINDOWEDGE = (style And WS_EX_WINDOWEDGE)
  281.         .WS_EX_CLIENTEDGE = (style And WS_EX_CLIENTEDGE)
  282.         .WS_EX_CONTEXTHELP = (style And WS_EX_CONTEXTHELP)
  283.         .WS_EX_RIGHT = (style And WS_EX_RIGHT)
  284.         .WS_EX_LEFT = (style And WS_EX_LEFT)
  285.         .WS_EX_RTLREADING = (style And WS_EX_RTLREADING)
  286.         .WS_EX_LTRREADING = (style And WS_EX_LTRREADING)
  287.         .WS_EX_LEFTSCROLLBAR = (style And WS_EX_LEFTSCROLLBAR)
  288.         .WS_EX_RIGHTSCROLLBAR = (style And WS_EX_RIGHTSCROLLBAR)
  289.         .WS_EX_CONTROLPARENT = (style And WS_EX_CONTROLPARENT)
  290.         .WS_EX_STATICEDGE = (style And WS_EX_STATICEDGE)
  291.         .WS_EX_APPWINDOW = (style And WS_EX_APPWINDOW)
  292.         .WS_EX_OVERLAPPEDWINDOW = (style And WS_EX_OVERLAPPEDWINDOW)
  293.         .WS_EX_PALETTEWINDOW = (style And WS_EX_PALETTEWINDOW)
  294.         .WS_EX_LAYERED = (style And WS_EX_LAYERED)
  295.         .WS_EX_NOINHERITLAYOUT = (style And WS_EX_NOINHERITLAYOUT)
  296.         .WS_EX_LAYOUTRTL = (style And WS_EX_LAYOUTRTL)
  297.         .WS_EX_NOACTIVATE = (style And WS_EX_NOACTIVATE)
  298.     End With
  299.     Set WinExStyle = objTmpWinExStyle
  300. End Sub
  301.  
  302. ' Show window styles for the selected window
  303. Public Sub GetWinStyle(hwnd As Long, WinStyle As clsWInStyle, Optional strWindow As String)
  304.     Dim style As Long
  305.     Dim useHwnd As Long
  306.     Dim objTmpWinStyle As clsWInStyle
  307.     Set objTmpWinStyle = New clsWInStyle
  308.     If hwnd Then
  309.         useHwnd = hwnd
  310.     Else
  311.         useHwnd = GetHwndFromWord(strWindow)
  312.     End If
  313.     ' Get the class info
  314.     style& = GetWindowLong&(useHwnd&, GWL_STYLE)
  315.     With objTmpWinStyle
  316.         .WS_BORDER = (style And WS_BORDER)
  317.         .WS_CAPTION = (style And WS_CAPTION)
  318.         .WS_CHILD = (style And WS_CHILD)
  319.         .WS_CLIPCHILDREN = (style And WS_CLIPCHILDREN)
  320.         .WS_CLIPSIBLINGS = (style And WS_CLIPSIBLINGS)
  321.         .WS_DISABLED = (style And WS_DISABLED)
  322.         .WS_DLGFRAME = (style And WS_DLGFRAME)
  323.         .WS_GROUP = (style And WS_GROUP)
  324.         .WS_HSCROLL = (style And WS_HSCROLL)
  325.         .WS_MAXIMIZE = (style And WS_MAXIMIZE)
  326.         .WS_MAXIMIZEBOX = (style And WS_MAXIMIZEBOX)
  327.         .WS_MINIMIZE = (style And WS_MINIMIZE)
  328.         .WS_MINIMIZEBOX = (style And WS_MINIMIZEBOX)
  329.         .WS_POPUP = (style And WS_POPUP)
  330.         .WS_SYSMENU = (style And WS_SYSMENU)
  331.         .WS_TABSTOP = (style And WS_TABSTOP)
  332.         .WS_THICKFRAME = (style And WS_THICKFRAME)
  333.         .WS_VISIBLE = (style And WS_VISIBLE)
  334.         .WS_VSCROLL = (style And WS_VSCROLL)
  335.     End With
  336.     Set WinStyle = objTmpWinStyle
  337. End Sub
  338.  
  339. ' Retrieve the name of a control in a specific window
  340. Private Function GetControlNameFromWindow(ByVal hwnd&)
  341.     Dim formnum As Integer
  342.     Dim ctlnum As Integer
  343.     For formnum = 0 To Forms.Count - 1
  344.         If Forms(formnum).hwnd = hwnd& Then
  345.             GetControlNameFromWindow = Forms(formnum).Name
  346.             Exit Function
  347.         End If
  348.         For ctlnum = 0 To Forms(formnum).Controls.Count - 1
  349.             On Error Resume Next
  350.             If Forms(formnum).Controls(ctlnum).hwnd = hwnd& Then
  351.                 If Err.Number = 0 Then
  352.                     GetControlNameFromWindow = Forms(formnum).Controls(ctlnum).Name
  353.                 End If
  354.                 Exit Function
  355.             End If
  356.         Next ctlnum
  357.     Next formnum
  358. End Function
  359.  
  360. ' Retrieve the name of a control
  361. Public Function GetCtlName(hwnd As Long, Optional strWindow As String) As String
  362.     Dim useHwnd As Long
  363.     If hwnd Then
  364.         useHwnd = hwnd
  365.     Else
  366.         useHwnd = GetHwndFromWord(strWindow)
  367.     End If
  368.     GetCtlName = GetControlNameFromWindow(useHwnd)
  369. End Function
  370.  
  371. ' load parent window of a child window
  372. Public Function GetParentWindow(hwnd As Long, Optional strWindow As String) As String
  373.     Dim useHwnd As Long, newhwnd As Long
  374.     Dim windowdesc As String
  375.     If hwnd Then
  376.         useHwnd = hwnd
  377.     Else
  378.         useHwnd = GetHwndFromWord(strWindow)
  379.     End If
  380.     newhwnd& = GetParent(hwnd)
  381.     If newhwnd& = 0 Then
  382.         GetParentWindow = vbNullString
  383.         Exit Function
  384.     End If
  385.     GetParentWindow = GetWindowDesc$(newhwnd&)
  386. End Function
  387.  
  388. ' load all the child windows of a specific window
  389. Public Function GetChild(hwnd As Long, Optional strWindow As String) As Boolean
  390.     Dim tHwnd As Long, i As Integer
  391.     i = 1
  392.     If hwnd Then
  393.         tHwnd = hwnd
  394.     Else
  395.         tHwnd = GetHwndFromWord(strWindow)
  396.     End If
  397.     ' It's first child is the specified window
  398.     'tHwnd = GetWindow(tHwnd, GW_CHILD)
  399.         
  400.     If tHwnd = 0 Then
  401.         GetChild = False
  402.         Exit Function
  403.     End If
  404.     Dim res As Double
  405.     Set objListTop = New clsWinView
  406.     res = EnumChildWindows(tHwnd, AddressOf CallBack_EnumChildWindows, tHwnd)
  407.     GetChild = True
  408. End Function
  409.  
  410. Public Sub GetOwnedWindow(hwnd As Long, Optional strWindow As String)
  411.     Dim useHwnd As Long
  412.     Dim dl As Long
  413.     If hwnd Then
  414.         useHwnd = hwnd
  415.     Else
  416.         useHwnd = GetHwndFromWord(strWindow)
  417.     End If
  418.     Set objListTop = New clsWinView
  419.     dl& = EnumWindows(AddressOf CallBack_EnumOwnedWindows, useHwnd)
  420.     Set objListTop = Nothing
  421. End Sub
  422.  
  423. Public Sub SetPointMode(hwnd As Long)
  424.     Dim dl&
  425.     dl& = SetCapture(hwnd)
  426. End Sub
  427.  
  428. Public Sub ResetPointMode(hwnd As Long)
  429.     If GetCapture() = hwnd Then ReleaseCapture
  430. End Sub
  431.  
  432. Public Function GetWindowFromPoint(hwnd As Long, x As Long, y As Long) As String
  433.     Dim pt As POINTAPI
  434.     Dim foundhWnd As Long
  435.     pt.x = x
  436.     pt.y = y
  437.     'ClientToScreen hwnd, pt
  438.     foundhWnd = WindowFromPoint(pt.x, pt.y)
  439.     GetWindowFromPoint = GetWindowDesc$(foundhWnd)
  440. End Function
  441.  
  442. Public Function GetHwndFromWord(strWindow As String) As Long
  443.     Dim p As Integer
  444.     p = InStr(strWindow, Chr$(9))
  445.     If p > 0 Then GetHwndFromWord = Val(Left$(strWindow, p - 1))
  446. End Function
  447.  
  448. Public Function GetBaseNameFromWord(strWindow As String) As String
  449.     Dim p As Integer, q As Integer
  450.     q = InStr(strWindow, Chr$(9))
  451.     If q > 0 Then p = InStr(q + 1, strWindow, Chr$(9))
  452.     If p > 0 Then GetBaseNameFromWord = Mid$(strWindow, q + 1, p - q - 1)
  453. End Function
  454.  
  455. Public Function GetClassNameFromWord(strWindow As String) As String
  456.     Dim p As Integer, q As Integer
  457.     Dim strTmp As String
  458.     For q = Len(strWindow) To 1 Step -1
  459.         If Mid(strWindow, q, 1) = Chr(9) Then Exit For
  460.         strTmp = Mid(strWindow, q, 1) + strTmp
  461.     Next
  462.     GetClassNameFromWord = strTmp
  463. End Function
  464.  
  465. ' Builds a string that describing the window in
  466. ' format handle, source application, class
  467. ' seperated by tabs.
  468. Public Function GetWindowDesc(hwnd As Long) As String
  469.     Dim desc As String
  470.     Dim tbuf As String
  471.     Dim inst As Long
  472.     Dim dl As Long
  473.     Dim hWndProcess As Long
  474.     ' Include the windows handle first
  475.     desc = "&H" + Hex(hwnd) + Chr(9)
  476.     ' Get name of source app
  477.     tbuf = String(256, 0) ' Predefine string length
  478.     dl = GetWindowThreadProcessId(hwnd, hWndProcess)
  479.     If hWndProcess = GetCurrentProcessId() Then
  480.         ' Get instance for window
  481.         inst = GetWindowLong(hwnd, GWL_HINSTANCE)
  482.         ' Get the module filename
  483.         dl = GetModuleFileName(inst, tbuf, 255)
  484.         tbuf = GetBaseName(tbuf)
  485.         tbuf = LPSTRToVBString$(tbuf)
  486.     Else
  487.         tbuf = "Foreign Window"
  488.     End If
  489.     ' And add it to the description
  490.     desc = desc + tbuf + Chr(9)
  491.     ' Add the class name
  492.     tbuf = String(256, 0) ' Initialize space again
  493.     dl = GetClassName(hwnd, tbuf, 255)
  494.     tbuf = LPSTRToVBString$(tbuf)
  495.     desc = desc + tbuf
  496.     GetWindowDesc = desc
  497. End Function
  498.  
  499. ' If source is a path, this function retrieves the
  500. ' basename, or filename sans path
  501. ' source MUST be a valid filename
  502. Private Function GetBaseName(ByVal source As String) As String
  503.     Do While InStr(source, "\") <> 0
  504.         source = Mid(source, InStr(source, "\") + 1)
  505.     Loop
  506.     If InStr(source, ":") <> 0 Then
  507.         source = Mid(source, InStr(source, ":") + 1)
  508.     End If
  509.     GetBaseName = source
  510. End Function
  511.  
  512. Public Function GetWindowTitle(ByVal hwnd As Long) As String
  513.     Dim sWindowText As String, r As Long
  514.     On Error Resume Next
  515.     sWindowText = Space(255)
  516.     r = GetWindowText(hwnd, sWindowText, 255)
  517.     sWindowText = Left(sWindowText, r)
  518.     GetWindowTitle = sWindowText
  519. End Function
  520.  
  521. Private Function LPSTRToVBString$(ByVal s$)
  522.     Dim nullpos&
  523.     nullpos& = InStr(s$, Chr$(0))
  524.     If nullpos > 0 Then
  525.         LPSTRToVBString = Left$(s$, nullpos - 1)
  526.     Else
  527.         LPSTRToVBString = ""
  528.     End If
  529. End Function
  530.  
  531.