home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch05 / winview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-02-16  |  22.0 KB  |  643 lines

  1. VERSION 4.00
  2. Begin VB.Form Winview 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "WinView"
  6.    ClientHeight    =   3555
  7.    ClientLeft      =   1440
  8.    ClientTop       =   2265
  9.    ClientWidth     =   7140
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   4245
  21.    Left            =   1380
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   237
  25.    ScaleMode       =   3  'Pixel
  26.    ScaleWidth      =   476
  27.    Top             =   1635
  28.    Width           =   7260
  29.    Begin VB.PictureBox picPoint2 
  30.       Height          =   375
  31.       Left            =   6240
  32.       ScaleHeight     =   345
  33.       ScaleWidth      =   645
  34.       TabIndex        =   9
  35.       Top             =   3060
  36.       Width           =   675
  37.    End
  38.    Begin VB.ListBox List1 
  39.       Appearance      =   0  'Flat
  40.       Height          =   1980
  41.       Left            =   240
  42.       TabIndex        =   8
  43.       Top             =   360
  44.       Width           =   6795
  45.    End
  46.    Begin VB.CommandButton CmdPosition 
  47.       Appearance      =   0  'Flat
  48.       BackColor       =   &H80000005&
  49.       Caption         =   "Position"
  50.       Height          =   435
  51.       Left            =   240
  52.       TabIndex        =   2
  53.       Top             =   2460
  54.       Width           =   975
  55.    End
  56.    Begin VB.CommandButton CmdSize 
  57.       Appearance      =   0  'Flat
  58.       BackColor       =   &H80000005&
  59.       Caption         =   "Size"
  60.       Height          =   435
  61.       Left            =   1320
  62.       TabIndex        =   3
  63.       Top             =   2460
  64.       Width           =   975
  65.    End
  66.    Begin VB.CommandButton CmdClassInfo 
  67.       Appearance      =   0  'Flat
  68.       BackColor       =   &H80000005&
  69.       Caption         =   "ClassInfo"
  70.       Height          =   435
  71.       Left            =   2400
  72.       TabIndex        =   4
  73.       Top             =   2460
  74.       Width           =   975
  75.    End
  76.    Begin VB.CommandButton CmdWinStyles 
  77.       Appearance      =   0  'Flat
  78.       BackColor       =   &H80000005&
  79.       Caption         =   "WinStyles"
  80.       Height          =   435
  81.       Left            =   3480
  82.       TabIndex        =   5
  83.       Top             =   2460
  84.       Width           =   1035
  85.    End
  86.    Begin VB.CommandButton CmdFlash 
  87.       Appearance      =   0  'Flat
  88.       BackColor       =   &H80000005&
  89.       Caption         =   "Flash"
  90.       Height          =   435
  91.       Left            =   4620
  92.       TabIndex        =   6
  93.       Top             =   2460
  94.       Width           =   975
  95.    End
  96.    Begin VB.CommandButton CmdCtlName 
  97.       Appearance      =   0  'Flat
  98.       BackColor       =   &H80000005&
  99.       Caption         =   "CtlName"
  100.       Height          =   435
  101.       Left            =   240
  102.       TabIndex        =   7
  103.       Top             =   3000
  104.       Width           =   975
  105.    End
  106.    Begin VB.CommandButton CmdParent 
  107.       Appearance      =   0  'Flat
  108.       BackColor       =   &H80000005&
  109.       Caption         =   "Parent"
  110.       Height          =   435
  111.       Left            =   1320
  112.       TabIndex        =   1
  113.       Top             =   3000
  114.       Width           =   975
  115.    End
  116.    Begin VB.Label lblHere 
  117.       Alignment       =   1  'Right Justify
  118.       BackColor       =   &H00FFFFFF&
  119.       Caption         =   "Click Here For point mode 2 -->"
  120.       Height          =   255
  121.       Left            =   3420
  122.       TabIndex        =   10
  123.       Top             =   3120
  124.       Width           =   2835
  125.    End
  126.    Begin Cbkd.Callback Callback1 
  127.       Left            =   2580
  128.       Top             =   3000
  129.       _Version        =   262144
  130.       _ExtentX        =   847
  131.       _ExtentY        =   847
  132.       _StockProps     =   0
  133.       Type            =   6
  134.    End
  135.    Begin VB.Label Label1 
  136.       Appearance      =   0  'Flat
  137.       BackColor       =   &H80000005&
  138.       ForeColor       =   &H80000008&
  139.       Height          =   195
  140.       Left            =   240
  141.       TabIndex        =   0
  142.       Top             =   60
  143.       Width           =   5415
  144.    End
  145.    Begin VB.Menu MenuLoadList 
  146.       Caption         =   "LoadList"
  147.       Begin VB.Menu MenuTopLevel 
  148.          Caption         =   "&TopLevel"
  149.          Shortcut        =   ^T
  150.       End
  151.       Begin VB.Menu MenuChildren 
  152.          Caption         =   "&Children"
  153.          Shortcut        =   ^C
  154.       End
  155.       Begin VB.Menu MenuOwned 
  156.          Caption         =   "&Owned"
  157.          Shortcut        =   ^O
  158.       End
  159.       Begin VB.Menu MenuPointed 
  160.          Caption         =   "&Pointed"
  161.          Shortcut        =   ^P
  162.       End
  163.       Begin VB.Menu MenuClear 
  164.          Caption         =   "C&lear"
  165.       End
  166.    End
  167. Attribute VB_Name = "Winview"
  168. Attribute VB_Creatable = False
  169. Attribute VB_Exposed = False
  170. Option Explicit
  171. ' Copyright 
  172.  1996 by Desaware. All Rights Reserved
  173. Public Function GetControlNameFromWindow(ByVal hwnd&)
  174.     Dim formnum%
  175.     Dim ctlnum%
  176.     For formnum% = 0 To Forms.Count - 1
  177.         If Forms(formnum%).hwnd = hwnd& Then
  178.             GetControlNameFromWindow = Forms(formnum%).Name
  179.             Exit Function
  180.         End If
  181.         For ctlnum% = 0 To Forms(formnum%).Controls.Count - 1
  182.             On Error Resume Next
  183.             If Forms(formnum%).Controls(ctlnum%).hwnd = hwnd& Then
  184.                 If Err.Number = 0 Then
  185.                     GetControlNameFromWindow = Forms(formnum%).Controls(ctlnum%).Name
  186.                 End If
  187.                 Exit Function
  188.             End If
  189.         Next ctlnum%
  190.     Next formnum%
  191. End Function
  192. '   lpData was passed by the EnumWindows call and contains
  193. '   the parent window handle that we are looking for.
  194. Private Sub Callback1_EnumWindows(hwnd As Long, lpData As Long, retval As Long)
  195.     ' If hWnd is owned by window in lpData,
  196.     ' Add it to the listbox
  197.     ' Was: If GetParent(hwnd) = CInt(lpData) Then
  198.     If GetParent(hwnd) = lpData Then
  199.         List1.AddItem GetWindowDesc$(hwnd)
  200.     End If
  201.     retval = 1  ' Continue enumeration
  202. End Sub
  203. ' Show class styles for the selected window
  204. Private Sub CmdClassInfo_Click()
  205.     Dim clsextra&, wndextra&    ' Change to long, though probably unnecessary
  206.     Dim style&      ' Changed to long
  207.     Dim useHwnd&    ' Changed to long
  208.     Dim crlf$
  209.     Dim outstring$, titlestring$
  210.     crlf$ = Chr$(13) + Chr$(10)
  211.     If List1.ListIndex < 0 Then
  212.         MsgBox "No windows selected", 0, "Error"
  213.         Exit Sub
  214.     End If
  215.     titlestring$ = List1.Text
  216.     useHwnd& = GetHwnd(titlestring$)
  217.     ' Get the class info
  218.     ' These all used to be GetClassWord and GCW_ constants
  219.     clsextra& = GetClassLong(useHwnd&, GCL_CBCLSEXTRA)
  220.     wndextra& = GetClassLong(useHwnd&, GCL_CBWNDEXTRA)
  221.     style& = GetClassLong(useHwnd&, GCL_STYLE)
  222.     outstring$ = "Class & Word Extra = " + Str$(clsextra&) + "," + Str$(wndextra&) + crlf$
  223.     If style& And CS_BYTEALIGNCLIENT Then
  224.         outstring$ = outstring$ + "CS_BYTEALIGNCLIENT" + crlf$
  225.     End If
  226.     If style& And CS_BYTEALIGNWINDOW Then
  227.         outstring$ = outstring$ + "CS_BYTEALIGNWINDOW" + crlf$
  228.     End If
  229.     If style& And CS_CLASSDC Then
  230.         outstring$ = outstring$ + "CS_CLASSDC" + crlf$
  231.     End If
  232.     If style& And CS_DBLCLKS Then
  233.         outstring$ = outstring$ + "CS_DBLCLKS" + crlf$
  234.     End If
  235.     ' Was CS_GLOBALCLASS (has same value)
  236.     If style& And CS_PUBLICCLASS Then
  237.         outstring$ = outstring$ + "CS_GLOBALCLASS" + crlf$
  238.     End If
  239.     If style& And CS_HREDRAW Then
  240.         outstring$ = outstring$ + "CS_HREDRAW" + crlf$
  241.     End If
  242.     If style& And CS_NOCLOSE Then
  243.         outstring$ = outstring$ + "CS_NOCLOSE" + crlf$
  244.     End If
  245.     If style& And CS_OWNDC Then
  246.         outstring$ = outstring$ + "CS_OWNDC" + crlf$
  247.     End If
  248.     If style& And CS_PARENTDC Then
  249.         outstring$ = outstring$ + "CS_PARENTDC" + crlf$
  250.     End If
  251.     If style& And CS_SAVEBITS Then
  252.         outstring$ = outstring$ + "CS_SAVEBITS" + crlf$
  253.     End If
  254.     If style& And CS_VREDRAW Then
  255.         outstring$ = outstring$ + "CS_VREDRAW" + crlf$
  256.     End If
  257.     MsgBox outstring$, 0, titlestring$
  258. End Sub
  259. ' Obtains the control name or form name of a Visual
  260. ' Basic form or control given the window handle.
  261. ' Non VB windows will have no form or control name
  262. Private Sub CmdCtlName_Click()
  263.     Dim titlestring$
  264.     Dim outputstring$
  265.     Dim useHwnd&
  266.     If List1.ListIndex < 0 Then
  267.         MsgBox "No windows selected", 0, "Error"
  268.         Exit Sub
  269.     End If
  270.     titlestring$ = List1.Text
  271.     useHwnd& = GetHwnd(titlestring$)
  272.     ' Was: outputstring$ = agGetControlName$(useHwnd&)
  273.     ' See text for reason for this change
  274.     outputstring$ = GetControlNameFromWindow(useHwnd&)
  275.     If outputstring$ = "" Then
  276.         MsgBox "Not a VB Form or Control", 0, titlestring$
  277.     Else
  278.         MsgBox "CtlName or FormName = " + outputstring$, 0, titlestring$
  279.     End If
  280. End Sub
  281. ' Flashes the caption of the selected window. This feature
  282. ' is typically attached to a timer when the code needs to
  283. ' "flash" a window caption to attract the users attention.
  284. ' Try clicking this button several times quickly for a
  285. ' visible window that has a caption to see the effect
  286. Private Sub CmdFlash_Click()
  287.     Dim titlestring$
  288.     Dim useHwnd&
  289.     Dim dl&
  290.     If List1.ListIndex < 0 Then
  291.         MsgBox "No windows selected", 0, "Error"
  292.         Exit Sub
  293.     End If
  294.     titlestring$ = List1.Text
  295.     useHwnd& = GetHwnd(titlestring$)
  296.     dl& = FlashWindow(useHwnd&, -1)
  297. End Sub
  298. Private Sub CmdParent_Click()
  299.     Dim hwnd&, newhwnd& ' Changed to long
  300.     Dim windowdesc$
  301.     If List1.ListIndex < 0 Then
  302.         MsgBox "No Window Selected", 0, "Error"
  303.         Exit Sub
  304.     End If
  305.     hwnd& = GetHwnd(List1.Text)
  306.     newhwnd& = GetParent(hwnd&)
  307.     If newhwnd& = 0 Then
  308.         MsgBox "Window has no parent", 0, "Window &H" + Hex$(hwnd&)
  309.         Exit Sub
  310.     End If
  311.     windowdesc$ = GetWindowDesc$(newhwnd&)
  312.     MsgBox windowdesc$, 0, "Parent of &H" + Hex$(hwnd&) + " is"
  313. End Sub
  314. Private Sub cmdPoint_Click()
  315. End Sub
  316. '   Show the position of the selected window
  317. Private Sub CmdPosition_Click()
  318.     Dim WindowRect As RECT
  319.     Dim useHwnd&
  320.     Dim crlf$
  321.     Dim outstring$, titlestring$
  322.     crlf$ = Chr$(13) + Chr$(10)
  323.     If List1.ListIndex < 0 Then
  324.         MsgBox "No windows selected", 0, "Error"
  325.         Exit Sub
  326.     End If
  327.     titlestring$ = List1.Text
  328.     useHwnd& = GetHwnd(titlestring$)
  329.     ' Get the rectangle describing the window
  330.     GetWindowRect useHwnd&, WindowRect
  331.     If IsIconic&(useHwnd&) Then
  332.         outstring$ = "Is Iconic" + crlf$
  333.     End If
  334.     If IsZoomed&(useHwnd&) Then
  335.         outstring$ = outstring$ + "Is Zoomed" + crlf$
  336.     End If
  337.     If IsWindowEnabled&(useHwnd&) Then
  338.         outstring$ = outstring$ + "Is Enabled" + crlf$
  339.     Else
  340.         outstring$ = outstring$ + "Is Disabled" + crlf$
  341.     End If
  342.     If IsWindowVisible&(useHwnd&) Then
  343.         outstring$ = outstring$ + "Is Visible" + crlf$
  344.     Else
  345.         outstring$ = outstring$ + "Is NOT Visible" + crlf$
  346.     End If
  347.     outstring$ = outstring$ + "Rect: " + Str$(WindowRect.Left) + ","
  348.     outstring$ = outstring$ + Str$(WindowRect.Top) + ","
  349.     outstring$ = outstring$ + Str$(WindowRect.Right) + ","
  350.     outstring$ = outstring$ + Str$(WindowRect.Bottom)
  351.     MsgBox outstring$, 0, titlestring$
  352. End Sub
  353. '   Show the size of the selected window
  354. Private Sub CmdSize_Click()
  355.     Dim WindowClientRect As RECT
  356.     Dim useHwnd&
  357.     Dim crlf$
  358.     Dim outstring$, titlestring$
  359.     crlf$ = Chr$(13) + Chr$(10)
  360.     If List1.ListIndex < 0 Then
  361.         MsgBox "No windows selected", 0, "Error"
  362.         Exit Sub
  363.     End If
  364.     titlestring$ = List1.Text
  365.     useHwnd& = GetHwnd(titlestring$)
  366.     ' Get the rectangle describing the window
  367.     GetClientRect useHwnd&, WindowClientRect
  368.     outstring$ = "Horiz Pixels: " + Str$(WindowClientRect.Right) + crlf$
  369.     outstring$ = outstring$ + "Vert Pixels: " + Str$(WindowClientRect.Bottom)
  370.     MsgBox outstring$, 0, titlestring$
  371. End Sub
  372. ' Show window styles for the selected window
  373. Private Sub CmdWinStyles_Click()
  374.     Dim style&
  375.     Dim useHwnd&    ' Was integer
  376.     Dim crlf$
  377.     Dim outstring$, titlestring$
  378.     crlf$ = Chr$(13) + Chr$(10)
  379.     If List1.ListIndex < 0 Then
  380.         MsgBox "No windows selected", 0, "Error"
  381.         Exit Sub
  382.     End If
  383.     titlestring$ = List1.Text
  384.     useHwnd& = GetHwnd(titlestring$)
  385.     ' Get the class info
  386.     style& = GetWindowLong&(useHwnd&, GWL_STYLE)
  387.     If style& And WS_BORDER Then
  388.         outstring$ = outstring$ + "WS_BORDER" + crlf$
  389.     End If
  390.     If style& And WS_CAPTION Then
  391.         outstring$ = outstring$ + "WS_CAPTION" + crlf$
  392.     End If
  393.     If style& And WS_CHILD Then
  394.         outstring$ = outstring$ + "WS_CHILD" + crlf$
  395.     End If
  396.     If style& And WS_CLIPCHILDREN Then
  397.         outstring$ = outstring$ + "WS_CLIPCHILDREN" + crlf$
  398.     End If
  399.     If style& And WS_CLIPSIBLINGS Then
  400.         outstring$ = outstring$ + "WS_CLIPSIBLINGS" + crlf$
  401.     End If
  402.     If style& And WS_DISABLED Then
  403.         outstring$ = outstring$ + "WS_DISABLED" + crlf$
  404.     End If
  405.     If style& And WS_DLGFRAME Then
  406.         outstring$ = outstring$ + "WS_DLGFRAME" + crlf$
  407.     End If
  408.     If style& And WS_GROUP Then
  409.         outstring$ = outstring$ + "WS_GROUP" + crlf$
  410.     End If
  411.     If style& And WS_HSCROLL Then
  412.         outstring$ = outstring$ + "WS_HSCROLL" + crlf$
  413.     End If
  414.     If style& And WS_MAXIMIZE Then
  415.         outstring$ = outstring$ + "WS_MAXIMIZE" + crlf$
  416.     End If
  417.     If style& And WS_MAXIMIZEBOX Then
  418.         outstring$ = outstring$ + "WS_MAXIMIZEBOX" + crlf$
  419.     End If
  420.     If style& And WS_MINIMIZE Then
  421.         outstring$ = outstring$ + "WS_MINIMIZE" + crlf$
  422.     End If
  423.     If style& And WS_MINIMIZEBOX Then
  424.         outstring$ = outstring$ + "WS_MINIMIZEBOX" + crlf$
  425.     End If
  426.     If style& And WS_POPUP Then
  427.         outstring$ = outstring$ + "WS_POPUP" + crlf$
  428.     End If
  429.     If style& And WS_SYSMENU Then
  430.         outstring$ = outstring$ + "WS_SYSMENU" + crlf$
  431.     End If
  432.     If style& And WS_TABSTOP Then
  433.         outstring$ = outstring$ + "WS_TABSTOP" + crlf$
  434.     End If
  435.     If style& And WS_THICKFRAME Then
  436.         outstring$ = outstring$ + "WS_THICKFRAME" + crlf$
  437.     End If
  438.     If style& And WS_VISIBLE Then
  439.         outstring$ = outstring$ + "WS_VISIBLE" + crlf$
  440.     End If
  441.     If style& And WS_VSCROLL Then
  442.         outstring$ = outstring$ + "WS_VSCROLL" + crlf$
  443.     End If
  444.     ' Note: We could tap the style& variable for class
  445.     ' styles as well (especially since it is easy to
  446.     ' determine the class for a window), but that is
  447.     ' beyond the scope of this sample program.
  448.     MsgBox outstring$, 0, titlestring$
  449. End Sub
  450. Private Sub Form_Load()
  451.     Dim tabsets&(2) ' Change to an array of longs
  452.     Dim dl&
  453.     tabsets(0) = 45
  454.     tabsets(1) = 110
  455.     dl = SendMessageLongByRef&(List1.hwnd, LB_SETTABSTOPS, 2, tabsets(0))
  456. End Sub
  457. '   If we're in point mode, record the current window
  458. '   in the listbox
  459. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  460.     If PointMode% <> -1 Then Exit Sub
  461.     List1.AddItem Label1.Caption
  462.     PointMode% = 0
  463.     Label1.Caption = ""
  464.     ' If capture is still held, release it - this is
  465.     ' actually not necessary in VB 1.0 as it seems to
  466.     ' release the capture anyway!
  467.     If GetCapture() = Winview.hwnd Then ReleaseCapture
  468. End Sub
  469. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  470.     Dim pt As POINTAPI
  471.     Dim foundhWnd&  ' Now a long
  472.     ' Only record window if we're in point mode
  473.     If PointMode% = 0 Then Exit Sub
  474.     pt.X = X
  475.     pt.Y = Y
  476.     ClientToScreen Winview.hwnd, pt
  477.     ' Was: foundhWnd% = WindowFromPointBynum%(agPOINTAPItoLong&(pt))
  478.     foundhWnd& = WindowFromPoint(pt.X, pt.Y)
  479.     Label1.Caption = GetWindowDesc$(foundhWnd)
  480. End Sub
  481. ' If source$ is a path, this function retrieves the
  482. ' basename, or filename sans path
  483. ' source$ MUST be a valid filename
  484. Private Function GetBaseName$(ByVal source$)
  485.     Do While InStr(source$, "\") <> 0
  486.         source$ = Mid$(source$, InStr(source$, "\") + 1)
  487.     Loop
  488.     If InStr(source$, ":") <> 0 Then
  489.         source$ = Mid$(source$, InStr(source$, ":") + 1)
  490.     End If
  491.     GetBaseName$ = source$
  492. End Function
  493. '   Builds a string descrbing the window in format
  494. '   handle, source application, class
  495. '   seperated by tabs
  496. '   Used to take an integer parameter, now a long
  497. Private Function GetWindowDesc$(hwnd&)
  498.     Dim desc$
  499.     Dim tbuf$
  500.     Dim inst&   ' Now a long
  501.     Dim dl&
  502.     Dim hWndProcess&
  503.     ' Include the windows handle first
  504.     desc$ = "&H" + Hex$(hwnd) + Chr$(9)
  505.     ' Get name of source app
  506.     tbuf$ = String$(256, 0) ' Predefine string length
  507.     ' Handling of process is different in Win32 - see text
  508.     dl& = GetWindowThreadProcessId(hwnd, hWndProcess)
  509.     If hWndProcess = GetCurrentProcessId() Then
  510.         ' Get instance for window
  511.         ' Was: inst% = GetWindowWord(hwnd%, GWW_HINSTANCE)
  512.         
  513.         inst& = GetWindowLong(hwnd&, GWL_HINSTANCE)
  514.         ' Get the module filename
  515.         ' Was: dummy% = GetModuleFileName(inst%, tbuf$, 255)
  516.         dl& = GetModuleFileName(inst, tbuf$, 255)
  517.         tbuf$ = GetBaseName(tbuf$)
  518.         ' The following two lines are equivalent
  519.         tbuf$ = agGetStringFromLPSTR$(tbuf$)
  520.         ' If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
  521.     Else
  522.         tbuf$ = "Foreign Window"
  523.     End If
  524.     ' And add it to the description
  525.     desc$ = desc$ + tbuf$ + Chr$(9)
  526.     ' Finally, add the class name
  527.     tbuf$ = String$(256, 0) ' Initialize space again
  528.     dl& = GetClassName(hwnd&, tbuf$, 255)
  529.     tbuf$ = agGetStringFromLPSTR$(tbuf$)
  530.     desc$ = desc$ + tbuf$
  531.     ' And return the description
  532.     GetWindowDesc$ = desc$
  533. End Function
  534. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  535.     If PointMode% <> -2 Then Exit Sub
  536.     List1.AddItem Label1.Caption
  537.     PointMode% = 0
  538.     Label1.Caption = ""
  539.     ' If capture is still held, release it - this is
  540.     ' actually not necessary in VB 1.0 as it seems to
  541.     ' release the capture anyway!
  542.     If GetCapture() = Winview.hwnd Then ReleaseCapture
  543. End Sub
  544. Private Sub MenuChildren_Click()
  545.     Dim hwnd&   ' Changed to long
  546.     Dim windowdesc$
  547.     ' Is there a window selected?
  548.     If List1.ListIndex < 0 Then
  549.         MsgBox "No Window Selected", 0, "Error"
  550.         Exit Sub
  551.     End If
  552.     windowdesc$ = List1.Text
  553.     hwnd = GetHwnd(windowdesc$)    ' Extract window handle
  554.     ' It's first child is the specified window
  555.     hwnd = GetWindow(hwnd, GW_CHILD)
  556.     If hwnd = 0 Then
  557.         MsgBox "No children found for this window", 0, "Error"
  558.         Exit Sub
  559.     End If
  560.     ' Clear the listbox
  561.     List1.Clear
  562.     ' Now load all the child windows
  563.     Do
  564.         List1.AddItem GetWindowDesc$(hwnd)
  565.         hwnd = GetWindow(hwnd, GW_HWNDNEXT)
  566.     Loop While hwnd <> 0
  567.     Label1.Caption = "Children of: " + "&" + windowdesc$
  568. End Sub
  569. '   Just clear the listbox
  570. Private Sub MenuClear_Click()
  571.     ' Clear the listbox
  572.     ' Was dummy% = SendMessageBynum&(agGetControlHwnd(List1), LB_RESETCONTENT, 0, 0&)
  573.     List1.Clear
  574. End Sub
  575. '   Show owned windows of the currently selected window
  576. Private Sub MenuOwned_Click()
  577.     Dim hwnd&   ' Switch to Long
  578.     Dim dl&
  579.     Dim windowdesc$
  580.     ' Is there a window selected?
  581.     If List1.ListIndex < 0 Then
  582.         MsgBox "No Window Selected", 0, "Error"
  583.         Exit Sub
  584.     End If
  585.     windowdesc$ = List1.Text
  586.     hwnd = GetHwnd(windowdesc$)    ' Extract window handle
  587.     ' Clear the listbox
  588.     List1.Clear
  589.     ' This uses the cbk.vbx control to obtain a callback
  590.     ' address for EnumWindows.
  591.     ' This will trigger the Callback1_EnumWindows event
  592.     ' for each top level window.  This technique could
  593.     ' also have been used in place of the GetWindow loop
  594.     ' in the MenuTopLevel_Click event.
  595.     ' Was: dummy% = EnumWindows(Callback1.ProcAddress, CLng(hwnd))
  596.     dl& = EnumWindows(Callback1.ProcAddress, hwnd)
  597.     If List1.ListCount = 0 Then
  598.         MsgBox "No owned windows found for this window", 0, "Error"
  599.         Label1.Caption = ""
  600.         Exit Sub
  601.     End If
  602.     Label1.Caption = "Owned windows of: " + "&" + windowdesc$
  603. End Sub
  604. Private Sub MenuPointed_Click()
  605.     Dim dl&
  606.     ' Let system know that we're in point mode
  607.     PointMode% = -1
  608.     dl& = SetCapture(Winview.hwnd)
  609. End Sub
  610. '   Loads the listbox with a list of all top level
  611. '   windows.
  612. Private Sub MenuTopLevel_Click()
  613.     Dim hwnd&
  614.     ' Clear the listbox
  615.     ' Was: dummy% = SendMessage&(agGetControlHwnd(List1), LB_RESETCONTENT, 0, 0&)
  616.     ' Could be: dummy& = SendMessage&(agGetControlHwnd(List1), LB_RESETCONTENT, 0, 0&)
  617.     ' But we might as well use:
  618.     List1.Clear
  619.     ' The desktop is the highest window
  620.     hwnd& = GetDesktopWindow()
  621.     ' It's first child is the 1st top level window
  622.     hwnd& = GetWindow(hwnd&, GW_CHILD)
  623.     ' Now load all top level windows
  624.     Do
  625.         List1.AddItem GetWindowDesc$(hwnd&)
  626.         hwnd& = GetWindow(hwnd&, GW_HWNDNEXT)
  627.     Loop While hwnd& <> 0
  628.     Label1.Caption = "Top level windows"
  629. End Sub
  630. Private Sub picPoint2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  631.     Dim dl&
  632.     ' Let system know that we're in point mode
  633.     PointMode% = -2
  634.     dl& = SetCapture(Winview.hwnd)
  635.     ' Initialize the label
  636.     Label1.Caption = GetWindowDesc$(picPoint2.hwnd)
  637. End Sub
  638. Private Function GetHwnd&(title$)
  639.     Dim p%
  640.     p% = InStr(title$, Chr$(9))
  641.     If p% > 0 Then GetHwnd& = Val(Left$(title$, p% - 1))
  642. End Function
  643.