home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch12 / query / query.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  7.3 KB  |  237 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Query about other Applications"
  4.    ClientHeight    =   3735
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3735
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "Start"
  14.       Height          =   375
  15.       Left            =   1080
  16.       TabIndex        =   12
  17.       Top             =   3240
  18.       Width           =   2415
  19.    End
  20.    Begin VB.TextBox Text1 
  21.       BackColor       =   &H80000004&
  22.       Height          =   375
  23.       Index           =   5
  24.       Left            =   1680
  25.       TabIndex        =   11
  26.       Text            =   "Text1"
  27.       Top             =   2520
  28.       Width           =   2775
  29.    End
  30.    Begin VB.TextBox Text1 
  31.       BackColor       =   &H80000004&
  32.       Height          =   375
  33.       Index           =   4
  34.       Left            =   1680
  35.       TabIndex        =   10
  36.       Text            =   "Text1"
  37.       Top             =   2040
  38.       Width           =   2775
  39.    End
  40.    Begin VB.TextBox Text1 
  41.       BackColor       =   &H80000004&
  42.       Height          =   375
  43.       Index           =   3
  44.       Left            =   1680
  45.       TabIndex        =   9
  46.       Text            =   "Text1"
  47.       Top             =   1560
  48.       Width           =   2775
  49.    End
  50.    Begin VB.TextBox Text1 
  51.       BackColor       =   &H80000004&
  52.       Height          =   375
  53.       Index           =   2
  54.       Left            =   1680
  55.       TabIndex        =   8
  56.       Text            =   "Text1"
  57.       Top             =   1080
  58.       Width           =   2775
  59.    End
  60.    Begin VB.TextBox Text1 
  61.       BackColor       =   &H80000004&
  62.       Height          =   375
  63.       Index           =   1
  64.       Left            =   1680
  65.       TabIndex        =   7
  66.       Text            =   "Text1"
  67.       Top             =   600
  68.       Width           =   2775
  69.    End
  70.    Begin VB.TextBox Text1 
  71.       BackColor       =   &H80000004&
  72.       Height          =   375
  73.       Index           =   0
  74.       Left            =   1680
  75.       TabIndex        =   6
  76.       Text            =   "Text1"
  77.       Top             =   120
  78.       Width           =   2775
  79.    End
  80.    Begin VB.Label Label6 
  81.       Caption         =   "Parent Caption:"
  82.       Height          =   255
  83.       Left            =   120
  84.       TabIndex        =   5
  85.       Top             =   2640
  86.       Width           =   1335
  87.    End
  88.    Begin VB.Label Label5 
  89.       Caption         =   "Parent Class:"
  90.       Height          =   255
  91.       Left            =   120
  92.       TabIndex        =   4
  93.       Top             =   2160
  94.       Width           =   1335
  95.    End
  96.    Begin VB.Label Label4 
  97.       Caption         =   "Parent Handle:"
  98.       Height          =   255
  99.       Left            =   120
  100.       TabIndex        =   3
  101.       Top             =   1680
  102.       Width           =   1335
  103.    End
  104.    Begin VB.Label Label3 
  105.       Caption         =   "Window Caption:"
  106.       Height          =   255
  107.       Left            =   120
  108.       TabIndex        =   2
  109.       Top             =   1200
  110.       Width           =   1335
  111.    End
  112.    Begin VB.Label Label2 
  113.       Caption         =   "Window Class:"
  114.       Height          =   255
  115.       Left            =   120
  116.       TabIndex        =   1
  117.       Top             =   720
  118.       Width           =   1335
  119.    End
  120.    Begin VB.Label Label1 
  121.       Caption         =   "Window Handle:"
  122.       Height          =   255
  123.       Left            =   120
  124.       TabIndex        =   0
  125.       Top             =   240
  126.       Width           =   1335
  127.    End
  128. Attribute VB_Name = "Form1"
  129. Attribute VB_GlobalNameSpace = False
  130. Attribute VB_Creatable = False
  131. Attribute VB_PredeclaredId = True
  132. Attribute VB_Exposed = False
  133. Option Explicit
  134. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  135.     ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
  136.     ByVal cy As Long, ByVal wFlags As Long) As Long
  137. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  138. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
  139.     ByVal yPoint As Long) As Long
  140. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  141. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
  142.     (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  143. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
  144.     (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  145. Const HWND_TOPMOST = -1
  146. Const SWP_SHOWWINDOW = &H40
  147. Private Type POINTAPI
  148.         X As Long
  149.         Y As Long
  150. End Type
  151. Private gStop As Boolean
  152. Private Sub Command1_Click()
  153.     Dim mousePT As POINTAPI
  154.     Dim prevWindow As Long
  155.     Dim curWindow As Long
  156.     Dim X As Long
  157.     Dim Y As Long
  158.     Dim tmpStr As String
  159.     Dim retValue As Long
  160.     Dim parentWnd As Long
  161.     'Track mouse here
  162.     If Command1.Caption = "Start" Then
  163.         
  164.         Command1.Caption = "Stop"
  165.         gStop = False
  166.         prevWindow = 0
  167.         
  168.         'Track until user stops
  169.         Do
  170.             'Stop tracking
  171.             If gStop = True Then Exit Do
  172.             
  173.             Call GetCursorPos(mousePT)
  174.             
  175.             X = mousePT.X
  176.             Y = mousePT.Y
  177.             
  178.             'Get window under mouse
  179.             curWindow = WindowFromPoint(X, Y)
  180.             
  181.             If curWindow <> prevWindow Then
  182.             
  183.                 tmpStr = String$(256, " ")
  184.                 prevWindow = curWindow
  185.                 
  186.                 retValue = GetClassName(curWindow, tmpStr, 255)
  187.                 tmpStr = Left$(tmpStr, InStr(tmpStr, vbNullChar) - 1)
  188.                 
  189.                 Text1(0).Text = curWindow
  190.                 Text1(1).Text = tmpStr
  191.                 
  192.                 retValue = GetWindowText(curWindow, tmpStr, 255)
  193.                 Text1(2).Text = tmpStr
  194.                 
  195.                 'Get parent window
  196.                 parentWnd = GetParent(curWindow)
  197.                 
  198.                 retValue = GetClassName(parentWnd, tmpStr, 255)
  199.                 'tmpStr = Left$(tmpStr, InStr(tmpStr, vbNullChar) - 1)
  200.                 
  201.                 Text1(3).Text = parentWnd
  202.                 Text1(4).Text = tmpStr
  203.               
  204.                 retValue = GetWindowText(parentWnd, tmpStr, 255)
  205.                 Text1(5).Text = tmpStr
  206.                                
  207.             End If
  208.             
  209.             
  210.             DoEvents
  211.             
  212.         Loop
  213.         
  214.            
  215.     'Stop tracking the mouse
  216.     Else
  217.         Command1.Caption = "Start"
  218.         gStop = True
  219.     End If
  220. End Sub
  221. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  222.     gStop = True
  223. End Sub
  224. Private Sub Form_Load()
  225.     Dim retValue As Long
  226.     If Command1.Caption = "Start" Then
  227.         gStop = False
  228.         'Command1.Caption = "Stop"
  229.         retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, _
  230.                                 Me.Width, Me.Height, SWP_SHOWWINDOW)
  231.                     
  232.     Else
  233.         gStop = True
  234.         Command1.Caption = "Start"
  235.     End If
  236. End Sub
  237.