home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / winview / winview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-15  |  20.9 KB  |  585 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  3. Begin VB.Form Winview 
  4.    Caption         =   "WinView"
  5.    ClientHeight    =   3555
  6.    ClientLeft      =   1335
  7.    ClientTop       =   1635
  8.    ClientWidth     =   11280
  9.    BeginProperty Font 
  10.       Name            =   "MS Sans Serif"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   700
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    ForeColor       =   &H80000008&
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    PaletteMode     =   1  'UseZOrder
  22.    ScaleHeight     =   237
  23.    ScaleMode       =   3  'Pixel
  24.    ScaleWidth      =   752
  25.    Begin VB.PictureBox picCatch 
  26.       Height          =   375
  27.       Left            =   6240
  28.       ScaleHeight     =   315
  29.       ScaleWidth      =   615
  30.       TabIndex        =   8
  31.       Top             =   3000
  32.       Width           =   675
  33.    End
  34.    Begin VB.CommandButton cmdPosition 
  35.       Caption         =   "Position"
  36.       Height          =   435
  37.       Left            =   240
  38.       TabIndex        =   2
  39.       Top             =   2460
  40.       Width           =   975
  41.    End
  42.    Begin VB.CommandButton cmdSize 
  43.       Caption         =   "Size"
  44.       Height          =   435
  45.       Left            =   1320
  46.       TabIndex        =   3
  47.       Top             =   2460
  48.       Width           =   975
  49.    End
  50.    Begin VB.CommandButton cmdClassInfo 
  51.       Caption         =   "ClassInfo"
  52.       Height          =   435
  53.       Left            =   2400
  54.       TabIndex        =   4
  55.       Top             =   2460
  56.       Width           =   975
  57.    End
  58.    Begin VB.CommandButton cmdWinStyles 
  59.       Caption         =   "WinStyles"
  60.       Height          =   435
  61.       Left            =   3480
  62.       TabIndex        =   5
  63.       Top             =   2460
  64.       Width           =   1035
  65.    End
  66.    Begin VB.CommandButton cmdFlash 
  67.       Caption         =   "Flash"
  68.       Height          =   435
  69.       Left            =   4620
  70.       TabIndex        =   6
  71.       Top             =   2460
  72.       Width           =   975
  73.    End
  74.    Begin VB.CommandButton cmdCtlName 
  75.       Caption         =   "CtlName"
  76.       Height          =   435
  77.       Left            =   240
  78.       TabIndex        =   7
  79.       Top             =   3000
  80.       Width           =   975
  81.    End
  82.    Begin VB.CommandButton cmdParent 
  83.       Caption         =   "Parent"
  84.       Height          =   435
  85.       Left            =   1320
  86.       TabIndex        =   1
  87.       Top             =   3000
  88.       Width           =   975
  89.    End
  90.    Begin ComctlLib.ListView lvwWindows 
  91.       Height          =   2010
  92.       Left            =   240
  93.       TabIndex        =   10
  94.       Top             =   360
  95.       Width           =   10770
  96.       _ExtentX        =   18997
  97.       _ExtentY        =   3545
  98.       View            =   3
  99.       LabelEdit       =   1
  100.       Sorted          =   -1  'True
  101.       LabelWrap       =   -1  'True
  102.       HideSelection   =   -1  'True
  103.       _Version        =   327682
  104.       ForeColor       =   -2147483640
  105.       BackColor       =   16777215
  106.       BorderStyle     =   1
  107.       Appearance      =   1
  108.       NumItems        =   4
  109.       BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  110.          Key             =   ""
  111.          Object.Tag             =   ""
  112.          Text            =   "hWnd"
  113.          Object.Width           =   2999
  114.       EndProperty
  115.       BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  116.          SubItemIndex    =   1
  117.          Key             =   ""
  118.          Object.Tag             =   ""
  119.          Text            =   "ExePath"
  120.          Object.Width           =   1587
  121.       EndProperty
  122.       BeginProperty ColumnHeader(3) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  123.          SubItemIndex    =   2
  124.          Key             =   ""
  125.          Object.Tag             =   ""
  126.          Text            =   "Class"
  127.          Object.Width           =   3175
  128.       EndProperty
  129.       BeginProperty ColumnHeader(4) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  130.          SubItemIndex    =   3
  131.          Key             =   ""
  132.          Object.Tag             =   ""
  133.          Text            =   "WindowText"
  134.          Object.Width           =   1587
  135.       EndProperty
  136.    End
  137.    Begin VB.Label lblHere 
  138.       Alignment       =   1  'Right Justify
  139.       Caption         =   "Click Here For point mode 2 -->"
  140.       Height          =   255
  141.       Left            =   3420
  142.       TabIndex        =   9
  143.       Top             =   3120
  144.       Width           =   2835
  145.    End
  146.    Begin VB.Label lblMsg 
  147.       Height          =   195
  148.       Left            =   240
  149.       TabIndex        =   0
  150.       Top             =   120
  151.       Width           =   5415
  152.    End
  153.    Begin VB.Menu mnuLoadList 
  154.       Caption         =   "LoadList"
  155.       Begin VB.Menu mnuTopLevel 
  156.          Caption         =   "&TopLevel"
  157.          Shortcut        =   ^T
  158.       End
  159.       Begin VB.Menu mnuChildren 
  160.          Caption         =   "&Children"
  161.          Shortcut        =   ^C
  162.       End
  163.       Begin VB.Menu mnuOwned 
  164.          Caption         =   "&Owned"
  165.          Shortcut        =   ^O
  166.       End
  167.       Begin VB.Menu MenuPointed 
  168.          Caption         =   "&Pointed"
  169.          Shortcut        =   ^P
  170.       End
  171.       Begin VB.Menu mnuClear 
  172.          Caption         =   "C&lear"
  173.       End
  174.    End
  175. Attribute VB_Name = "Winview"
  176. Attribute VB_GlobalNameSpace = False
  177. Attribute VB_Creatable = False
  178. Attribute VB_PredeclaredId = True
  179. Attribute VB_Exposed = False
  180. Option Explicit
  181. Private Enum enPointMode
  182.     enPointModeOff = 0
  183.     enPointModeMenu = 1
  184.     enPointModePic = 2
  185. End Enum
  186. Private genPointMode As enPointMode
  187. Private Sub Form_Load()
  188.     SetListviewStyle lvwWindows.hWnd, LVS_EX_FULLROWSELECT, True
  189. End Sub
  190. ' If point mode was started via menu, record the current window
  191. ' in the listbox
  192. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  193.     If genPointMode <> enPointModeMenu Then Exit Sub
  194.     AddToList lblMsg.Caption
  195.     genPointMode = enPointModeOff
  196.     lblMsg.Caption = ""
  197.     ' If capture is still held, release it
  198.     If GetCapture() = Me.hWnd Then ReleaseCapture
  199. End Sub
  200. ' If point mode was started via PictureBox, record the current window
  201. ' in the listbox
  202. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  203.     If genPointMode <> enPointModePic Then Exit Sub
  204.     AddToList lblMsg.Caption
  205.     genPointMode = enPointModeOff
  206.     lblMsg.Caption = ""
  207.     ' If capture is still held, release it
  208.     If GetCapture() = Me.hWnd Then ReleaseCapture
  209. End Sub
  210. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  211.     Dim tPT As POINTAPI
  212.     Dim hWndFound As Long
  213.     ' Only record window if we're in point mode
  214.     If genPointMode = enPointModeOff Then Exit Sub
  215.     ' convert clienet-coordinates to logical-coordinates
  216.     tPT.x = x
  217.     tPT.y = y
  218.     ClientToScreen Me.hWnd, tPT
  219.     ' get Window-Handle and Description
  220.     hWndFound = WindowFromPoint(tPT.x, tPT.y)
  221.     lblMsg.Caption = GetWindowDesc(hWndFound)
  222. End Sub
  223. '------------------------------------------------------------------------------
  224. ' Show the position of the selected window
  225. Private Sub cmdPosition_Click()
  226.     Dim tRECTWnd As RECT
  227.     Dim hWnd As Long
  228.     Dim sOut As String
  229.     Dim sTitle As String
  230.     If lvwWindows.SelectedItem Is Nothing Then
  231.         MsgBox "No windows selected", 0, "Error"
  232.         Exit Sub
  233.     End If
  234.     sTitle = lvwWindows.SelectedItem
  235.     hWnd = GetHWnd(sTitle)
  236.     ' Get the rectangle describing the window
  237.     GetWindowRect hWnd, tRECTWnd
  238.     If IsIconic(hWnd) Then sOut = "Is Iconic" & vbCrLf
  239.     If IsZoomed(hWnd) Then sOut = sOut & "Is Zoomed" & vbCrLf
  240.     If IsWindowEnabled(hWnd) Then
  241.         sOut = sOut & "Is Enabled" & vbCrLf
  242.     Else
  243.         sOut = sOut & "Is Disabled" & vbCrLf
  244.     End If
  245.     If IsWindowVisible(hWnd) Then
  246.         sOut = sOut & "Is Visible" & vbCrLf
  247.     Else
  248.         sOut = sOut & "Is NOT Visible" & vbCrLf
  249.     End If
  250.     With tRECTWnd
  251.         sOut = sOut & "Rect: " & CStr(.Left) & ", "
  252.         sOut = sOut & CStr(.Top) & ", "
  253.         sOut = sOut & CStr(.Right) & ", "
  254.         sOut = sOut & CStr(.Bottom)
  255.     End With
  256.     MsgBox sOut, 0, sTitle
  257. End Sub
  258. ' Show the size of the selected window
  259. Private Sub cmdSize_Click()
  260.     Dim tRECTWndClient As RECT
  261.     Dim hWnd As Long
  262.     Dim sOut As String
  263.     Dim sTitle As String
  264.     If lvwWindows.SelectedItem Is Nothing Then
  265.         MsgBox "No windows selected", 0, "Error"
  266.         Exit Sub
  267.     End If
  268.     sTitle = lvwWindows.SelectedItem
  269.     hWnd = GetHWnd(sTitle)
  270.     ' Get the rectangle describing the window
  271.     GetClientRect hWnd, tRECTWndClient
  272.     sOut = "Horiz Pixels: " & CStr(tRECTWndClient.Right) & vbCrLf
  273.     sOut = sOut & "Vert Pixels: " & CStr(tRECTWndClient.Bottom)
  274.     MsgBox sOut, 0, sTitle
  275. End Sub
  276. ' Show class styles for the selected window
  277. Private Sub cmdClassInfo_Click()
  278.     Dim lClsExtra As Long
  279.     Dim lWndExtra As Long
  280.     Dim lStyle As Long
  281.     Dim hWnd As Long
  282.     Dim sOut As String
  283.     Dim sTitle As String
  284.     If lvwWindows.SelectedItem Is Nothing Then
  285.         MsgBox "No windows selected", 0, "Error"
  286.         Exit Sub
  287.     End If
  288.     sTitle = lvwWindows.SelectedItem
  289.     hWnd = GetHWnd(sTitle)
  290.     ' Get the class info
  291.     ' These all used to be GetClassWord and GCW_ constants
  292.     lClsExtra = GetClassLong(hWnd, GCL_CBCLSEXTRA)
  293.     lWndExtra = GetClassLong(hWnd, GCL_CBWNDEXTRA)
  294.     lStyle = GetClassLong(hWnd, GCL_STYLE)
  295.     sOut = "Class & Word Extra = " & CStr(lClsExtra) & ", " & _
  296.                 CStr(lWndExtra) & vbCrLf
  297.                 
  298.     If lStyle And CS_BYTEALIGNCLIENT Then sOut = sOut & "CS_BYTEALIGNCLIENT" & vbCrLf
  299.     If lStyle And CS_BYTEALIGNWINDOW Then sOut = sOut & "CS_BYTEALIGNWINDOW" & vbCrLf
  300.     If lStyle And CS_CLASSDC Then sOut = sOut & "CS_CLASSDC" & vbCrLf
  301.     If lStyle And CS_DBLCLKS Then sOut = sOut & "CS_DBLCLKS" & vbCrLf
  302.     ' Was CS_GLOBALCLASS (has same value)
  303.     If lStyle And CS_PUBLICCLASS Then sOut = sOut & "CS_GLOBALCLASS" & vbCrLf
  304.     If lStyle And CS_HREDRAW Then sOut = sOut & "CS_HREDRAW" & vbCrLf
  305.     If lStyle And CS_NOCLOSE Then sOut = sOut & "CS_NOCLOSE" & vbCrLf
  306.     If lStyle And CS_OWNDC Then sOut = sOut & "CS_OWNDC" & vbCrLf
  307.     If lStyle And CS_PARENTDC Then sOut = sOut & "CS_PARENTDC" & vbCrLf
  308.     If lStyle And CS_SAVEBITS Then sOut = sOut & "CS_SAVEBITS" & vbCrLf
  309.     If lStyle And CS_VREDRAW Then sOut = sOut & "CS_VREDRAW" & vbCrLf
  310.     If lStyle And CS_NOKEYCVT Then sOut = sOut & "CS_NOKEYCVT" & vbCrLf
  311.     If lStyle And CS_KEYCVTWINDOW Then sOut = sOut & "CS_KEYCVTWINDOW" & vbCrLf
  312.     MsgBox sOut, 0, sTitle
  313. End Sub
  314. ' Show window styles for the selected window
  315. Private Sub cmdWinStyles_Click()
  316.     Dim lStyle As Long
  317.     Dim hWnd As Long
  318.     Dim sOut As String
  319.     Dim sTitle As String
  320.     If lvwWindows.SelectedItem Is Nothing Then
  321.         MsgBox "No windows selected", 0, "Error"
  322.         Exit Sub
  323.     End If
  324.     sTitle = lvwWindows.SelectedItem
  325.     hWnd = GetHWnd(sTitle)
  326.     ' Get the class info
  327.     lStyle = GetWindowLong(hWnd, GWL_STYLE)
  328.     If lStyle And WS_BORDER Then sOut = sOut & "WS_BORDER" & vbCrLf
  329.     If lStyle And WS_CAPTION Then sOut = sOut & "WS_CAPTION" & vbCrLf
  330.     If lStyle And WS_CHILD Then sOut = sOut & "WS_CHILD" & vbCrLf
  331.     If lStyle And WS_CLIPCHILDREN Then sOut = sOut & "WS_CLIPCHILDREN" & vbCrLf
  332.     If lStyle And WS_CLIPSIBLINGS Then sOut = sOut & "WS_CLIPSIBLINGS" & vbCrLf
  333.     If lStyle And WS_DISABLED Then sOut = sOut & "WS_DISABLED" & vbCrLf
  334.     If lStyle And WS_DLGFRAME Then sOut = sOut & "WS_DLGFRAME" & vbCrLf
  335.     If lStyle And WS_GROUP Then sOut = sOut & "WS_GROUP" & vbCrLf
  336.     If lStyle And WS_HSCROLL Then sOut = sOut & "WS_HSCROLL" & vbCrLf
  337.     If lStyle And WS_MAXIMIZE Then sOut = sOut & "WS_MAXIMIZE" & vbCrLf
  338.     If lStyle And WS_MAXIMIZEBOX Then sOut = sOut & "WS_MAXIMIZEBOX" & vbCrLf
  339.     If lStyle And WS_MINIMIZE Then sOut = sOut & "WS_MINIMIZE" & vbCrLf
  340.     If lStyle And WS_MINIMIZEBOX Then sOut = sOut & "WS_MINIMIZEBOX" & vbCrLf
  341.     If lStyle And WS_POPUP Then sOut = sOut & "WS_POPUP" & vbCrLf
  342.     If lStyle And WS_SYSMENU Then sOut = sOut & "WS_SYSMENU" & vbCrLf
  343.     If lStyle And WS_TABSTOP Then sOut = sOut & "WS_TABSTOP" & vbCrLf
  344.     If lStyle And WS_THICKFRAME Then sOut = sOut & "WS_THICKFRAME" & vbCrLf
  345.     If lStyle And WS_VISIBLE Then sOut = sOut & "WS_VISIBLE" & vbCrLf
  346.     If lStyle And WS_VSCROLL Then sOut = sOut & "WS_VSCROLL" & vbCrLf
  347.     ' Note: We could tap the lStyle variable for class
  348.     ' styles as well (especially since it is easy to
  349.     ' determine the class for a window), but that is
  350.     ' beyond the scope of this sample program.
  351.     MsgBox sOut, 0, sTitle
  352. End Sub
  353. ' Flashes the caption of the selected window. This feature
  354. ' is typically attached to a timer when the code needs to
  355. ' "flash" a window caption to attract the users attention.
  356. ' Try clicking this button several times quickly for a
  357. ' visible window that has a caption to see the effect
  358. Private Sub cmdFlash_Click()
  359.     Dim hWnd As Long
  360.     Dim sTitle As String
  361.     Dim lRet As Long
  362.     If lvwWindows.SelectedItem Is Nothing Then
  363.         MsgBox "No windows selected", 0, "Error"
  364.         Exit Sub
  365.     End If
  366.     sTitle = lvwWindows.SelectedItem
  367.     hWnd = GetHWnd(sTitle)
  368.     lRet = FlashWindow(hWnd, -1)
  369. End Sub
  370. ' Obtains the control name or form name of a Visual
  371. ' Basic form or control given the window handle.
  372. ' Non VB windows will have no form or control name
  373. Private Sub cmdCtlName_Click()
  374.     Dim sTitle As String
  375.     Dim sOut As String
  376.     Dim hWnd As Long
  377.     If lvwWindows.SelectedItem Is Nothing Then
  378.         MsgBox "No windows selected", 0, "Error"
  379.         Exit Sub
  380.     End If
  381.     sTitle = lvwWindows.SelectedItem
  382.     hWnd = GetHWnd(sTitle)
  383.     sOut = GetControlNameFromWindow(hWnd)
  384.     If Len(sOut) = 0 Then
  385.         MsgBox "Not a VB Form or Control", 0, sTitle
  386.     Else
  387.         MsgBox "CtlName or FormName = " & sOut, 0, sTitle
  388.     End If
  389. End Sub
  390. Private Sub cmdParent_Click()
  391.     Dim hWnd As Long
  392.     Dim sTitle As String
  393.     Dim hParent As Long
  394.     Dim sDescr As String
  395.     If lvwWindows.SelectedItem Is Nothing Then
  396.         MsgBox "No windows selected", 0, "Error"
  397.         Exit Sub
  398.     End If
  399.     sTitle = lvwWindows.SelectedItem
  400.     hWnd = GetHWnd(sTitle)
  401.     hParent = GetParent(hWnd)
  402.     If hParent = 0 Then
  403.         MsgBox "Window has no parent", 0, "Window &H" & Hex$(hWnd)
  404.         Exit Sub
  405.     End If
  406.     sDescr = GetWindowDesc(hParent)
  407.     MsgBox sDescr, 0, "Parent of &H" & Hex$(hWnd) & " is"
  408. End Sub
  409. Private Sub picCatch_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  410.     Dim lRet As Long
  411.     ' Let system know that we're in point mode
  412.     genPointMode = enPointModePic
  413.     lRet = SetCapture(Me.hWnd)
  414.     ' Initialize the label
  415.     lblMsg.Caption = GetWindowDesc(picCatch.hWnd)
  416. End Sub
  417. '   Loads the listbox with a list of all top level
  418. '   windows.
  419. Private Sub mnuTopLevel_Click()
  420.     Dim hWnd As Long
  421.     ' Clear the listbox
  422.     lvwWindows.ListItems.Clear
  423.     ' The desktop is the highest window
  424.     hWnd = GetDesktopWindow()
  425.     ' It's first child is the 1st top level window
  426.     hWnd = GetWindow(hWnd, GW_CHILD)
  427.     ' Now load all top level windows
  428.     Do
  429.         AddToList GetWindowDesc(hWnd)
  430.         hWnd = GetWindow(hWnd, GW_HWNDNEXT)
  431.     Loop While hWnd <> 0
  432.     lblMsg.Caption = "Top level windows"
  433.     Set lvwWindows.SelectedItem = lvwWindows.ListItems(1)
  434. End Sub
  435. Private Sub mnuChildren_Click()
  436.     Dim hWnd As Long
  437.     Dim sTitle As String
  438.     ' Is there a window selected?
  439.     If lvwWindows.SelectedItem Is Nothing Then
  440.         MsgBox "No windows selected", 0, "Error"
  441.         Exit Sub
  442.     End If
  443.     sTitle = lvwWindows.SelectedItem
  444.     hWnd = GetHWnd(sTitle)
  445.     ' It's first child is the specified window
  446.     hWnd = GetWindow(hWnd, GW_CHILD)
  447.     If hWnd = 0 Then
  448.         MsgBox "No children found for this window", 0, "Error"
  449.         Exit Sub
  450.     End If
  451.     ' Clear the listbox
  452.     lvwWindows.ListItems.Clear
  453.     ' Now load all the child windows
  454.     Do
  455.         AddToList GetWindowDesc(hWnd)
  456.         hWnd = GetWindow(hWnd, GW_HWNDNEXT)
  457.     Loop While hWnd <> 0
  458.     Set lvwWindows.SelectedItem = lvwWindows.ListItems(1)
  459.     lblMsg.Caption = "Children of: " & sTitle
  460. End Sub
  461. '   Show owned windows of the currently selected window
  462. Private Sub mnuOwned_Click()
  463.     Dim hWnd As Long
  464.     Dim sTitle As String
  465.     Dim lRet As Long
  466.     ' Is there a window selected?
  467.     If lvwWindows.SelectedItem Is Nothing Then
  468.         MsgBox "No windows selected", 0, "Error"
  469.         Exit Sub
  470.     End If
  471.     sTitle = lvwWindows.SelectedItem
  472.     hWnd = GetHWnd(sTitle)
  473.     ' Clear the listbox
  474.     lvwWindows.ListItems.Clear
  475.     ' This uses VB5's support for callbacks to a callback
  476.     ' address for EnumWindows.
  477.     ' This will trigger the Callback1_EnumWindows function
  478.     ' for each top level window.  This technique could
  479.     ' also have been used in place of the GetWindow loop
  480.     ' in the mnuTopLevel_Click event.
  481.     lRet = EnumWindows(AddressOf Callback1_EnumWindows, hWnd)
  482.     If lvwWindows.ListItems.Count = 0 Then
  483.         MsgBox "No owned windows found for this window", 0, "Error"
  484.         lblMsg.Caption = ""
  485.         Exit Sub
  486.     End If
  487.     lblMsg.Caption = "Owned windows of: " & sTitle
  488. End Sub
  489. Private Sub mnuPointed_Click()
  490.     Dim lRet As Long
  491.     ' Let system know that we're in point mode
  492.     genPointMode = enPointModeMenu
  493.     lRet = SetCapture(Me.hWnd)
  494. End Sub
  495. '   Just clear the listbox
  496. Private Sub mnuClear_Click()
  497.     lvwWindows.ListItems.Clear
  498. End Sub
  499. Private Function GetHWnd(ByVal vsTitle As String) As Long
  500.     Dim lPos As Long
  501.     lPos = InStr(vsTitle, vbTab)
  502.     If lPos > 0 Then
  503.         GetHWnd = Val(Left$(vsTitle, lPos - 1))
  504.     Else
  505.         GetHWnd = Val(vsTitle)
  506.     End If
  507. End Function
  508. ' Builds a string describing the window in format
  509. ' handle, source application, class
  510. ' seperated by tabs
  511. ' This function needs to be public since it is called by the
  512. ' callback function in the Winview1 module
  513. Public Function GetWindowDesc(hWnd As Long) As String
  514.     Dim sDesc As String
  515.     Dim sTemp As String
  516.     Dim hInst As Long
  517.     Dim lRet As Long
  518.     Dim hWndProcessID As Long
  519.     ' Include the windows handle first
  520.     sDesc = "&H" & Hex$(hWnd) & vbTab
  521.     ' Get name of source app
  522.     sTemp = String$(256, 0) ' Predefine string length
  523.     lRet = GetWindowThreadProcessId(hWnd, hWndProcessID)
  524.     If hWndProcessID = GetCurrentProcessId() Then
  525.         ' Get instance for window
  526.         hInst = GetWindowLong(hWnd, GWL_HINSTANCE)
  527.         ' Get the module filename
  528.         lRet = GetModuleFileName(hInst, sTemp, 255)
  529.         sTemp = LPSTRToStr(sTemp)
  530.         
  531.         sTemp = GetBaseName(sTemp)
  532.     Else
  533.         If SupportsToolHelp() Then
  534.             sTemp = GetBaseName(GetWin95ModuleName(hWndProcessID))
  535.         ElseIf IsNT() And SupportsPSAPI() Then
  536.             sTemp = GetBaseName(GetNTModuleName(hWndProcessID))
  537.         End If
  538.     End If
  539.     ' And add it to the description
  540.     sDesc = sDesc & sTemp & vbTab
  541.     ' Finally, add the class name
  542.     sTemp = String$(256, 0) ' Initialize space again
  543.     lRet = GetClassName(hWnd, sTemp, 255)
  544.     sTemp = LPSTRToStr(sTemp)
  545.     sDesc = sDesc & sTemp & vbTab
  546.     sTemp = String$(256, 0) ' Predefine string length
  547.     lRet = GetWindowText(hWnd, sTemp, 255)
  548.     sTemp = LPSTRToStr(sTemp)
  549.     sDesc = sDesc & sTemp
  550.     ' And return the description
  551.     GetWindowDesc = sDesc
  552. End Function
  553. Public Function GetControlNameFromWindow(ByVal hWnd As Long)
  554.     Dim nForm As Integer
  555.     Dim nCtl As Integer
  556.     For nForm = 0 To Forms.Count - 1
  557.         If Forms(nForm).hWnd = hWnd Then
  558.             GetControlNameFromWindow = Forms(nForm).Name
  559.             Exit Function
  560.         End If
  561.         
  562.         For nCtl = 0 To Forms(nCtl).Controls.Count - 1
  563.             On Error Resume Next
  564.             If Forms(nForm).Controls(nCtl).hWnd = hWnd Then
  565.                 If Err.Number = 0 Then
  566.                     GetControlNameFromWindow = Forms(nForm).Controls(nCtl).Name
  567.                 End If
  568.                 Exit Function
  569.             End If
  570.         Next nCtl
  571.     Next nForm
  572. End Function
  573. ' If sPath is a path, this function retrieves the
  574. ' basename, or filename sans path
  575. ' sPath MUST be a valid filename
  576. Private Function GetBaseName(ByVal vsPath As String) As String
  577.     Do While InStr(vsPath, "\") <> 0
  578.         vsPath = Mid$(vsPath, InStr(vsPath, "\") + 1)
  579.     Loop
  580.     If InStr(vsPath, ":") <> 0 Then
  581.         vsPath = Mid$(vsPath, InStr(vsPath, ":") + 1)
  582.     End If
  583.     GetBaseName = vsPath
  584. End Function
  585.