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 / samples5 / ch05 / winview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  21.4 KB  |  625 lines

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