home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch13 / query / query.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-04-30  |  10.8 KB  |  331 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Query about other Applications"
  4.    ClientHeight    =   3675
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4905
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3675
  10.    ScaleWidth      =   4905
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "Start"
  14.       BeginProperty Font 
  15.          Name            =   "Verdana"
  16.          Size            =   9
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   465
  24.       Left            =   3120
  25.       TabIndex        =   12
  26.       Top             =   3105
  27.       Width           =   1665
  28.    End
  29.    Begin VB.TextBox Text1 
  30.       BackColor       =   &H80000004&
  31.       BeginProperty Font 
  32.          Name            =   "Verdana"
  33.          Size            =   9
  34.          Charset         =   0
  35.          Weight          =   400
  36.          Underline       =   0   'False
  37.          Italic          =   0   'False
  38.          Strikethrough   =   0   'False
  39.       EndProperty
  40.       Height          =   375
  41.       Index           =   5
  42.       Left            =   1995
  43.       TabIndex        =   11
  44.       Top             =   2550
  45.       Width           =   2775
  46.    End
  47.    Begin VB.TextBox Text1 
  48.       BackColor       =   &H80000004&
  49.       BeginProperty Font 
  50.          Name            =   "Verdana"
  51.          Size            =   9
  52.          Charset         =   0
  53.          Weight          =   400
  54.          Underline       =   0   'False
  55.          Italic          =   0   'False
  56.          Strikethrough   =   0   'False
  57.       EndProperty
  58.       Height          =   375
  59.       Index           =   4
  60.       Left            =   1995
  61.       TabIndex        =   10
  62.       Top             =   2070
  63.       Width           =   2775
  64.    End
  65.    Begin VB.TextBox Text1 
  66.       BackColor       =   &H80000004&
  67.       BeginProperty Font 
  68.          Name            =   "Verdana"
  69.          Size            =   9
  70.          Charset         =   0
  71.          Weight          =   400
  72.          Underline       =   0   'False
  73.          Italic          =   0   'False
  74.          Strikethrough   =   0   'False
  75.       EndProperty
  76.       Height          =   375
  77.       Index           =   3
  78.       Left            =   1995
  79.       TabIndex        =   9
  80.       Top             =   1590
  81.       Width           =   2775
  82.    End
  83.    Begin VB.TextBox Text1 
  84.       BackColor       =   &H80000004&
  85.       BeginProperty Font 
  86.          Name            =   "Verdana"
  87.          Size            =   9
  88.          Charset         =   0
  89.          Weight          =   400
  90.          Underline       =   0   'False
  91.          Italic          =   0   'False
  92.          Strikethrough   =   0   'False
  93.       EndProperty
  94.       Height          =   375
  95.       Index           =   2
  96.       Left            =   1995
  97.       TabIndex        =   8
  98.       Top             =   1110
  99.       Width           =   2775
  100.    End
  101.    Begin VB.TextBox Text1 
  102.       BackColor       =   &H80000004&
  103.       BeginProperty Font 
  104.          Name            =   "Verdana"
  105.          Size            =   9
  106.          Charset         =   0
  107.          Weight          =   400
  108.          Underline       =   0   'False
  109.          Italic          =   0   'False
  110.          Strikethrough   =   0   'False
  111.       EndProperty
  112.       Height          =   375
  113.       Index           =   1
  114.       Left            =   1995
  115.       TabIndex        =   7
  116.       Top             =   630
  117.       Width           =   2775
  118.    End
  119.    Begin VB.TextBox Text1 
  120.       BackColor       =   &H80000004&
  121.       BeginProperty Font 
  122.          Name            =   "Verdana"
  123.          Size            =   9
  124.          Charset         =   0
  125.          Weight          =   400
  126.          Underline       =   0   'False
  127.          Italic          =   0   'False
  128.          Strikethrough   =   0   'False
  129.       EndProperty
  130.       Height          =   375
  131.       Index           =   0
  132.       Left            =   1995
  133.       TabIndex        =   6
  134.       Top             =   150
  135.       Width           =   2775
  136.    End
  137.    Begin VB.Label Label6 
  138.       Caption         =   "Parent Caption:"
  139.       BeginProperty Font 
  140.          Name            =   "Verdana"
  141.          Size            =   9
  142.          Charset         =   0
  143.          Weight          =   400
  144.          Underline       =   0   'False
  145.          Italic          =   0   'False
  146.          Strikethrough   =   0   'False
  147.       EndProperty
  148.       Height          =   255
  149.       Left            =   75
  150.       TabIndex        =   5
  151.       Top             =   2610
  152.       Width           =   1815
  153.    End
  154.    Begin VB.Label Label5 
  155.       Caption         =   "Parent Class:"
  156.       BeginProperty Font 
  157.          Name            =   "Verdana"
  158.          Size            =   9
  159.          Charset         =   0
  160.          Weight          =   400
  161.          Underline       =   0   'False
  162.          Italic          =   0   'False
  163.          Strikethrough   =   0   'False
  164.       EndProperty
  165.       Height          =   255
  166.       Left            =   75
  167.       TabIndex        =   4
  168.       Top             =   2130
  169.       Width           =   1335
  170.    End
  171.    Begin VB.Label Label4 
  172.       Caption         =   "Parent Handle:"
  173.       BeginProperty Font 
  174.          Name            =   "Verdana"
  175.          Size            =   9
  176.          Charset         =   0
  177.          Weight          =   400
  178.          Underline       =   0   'False
  179.          Italic          =   0   'False
  180.          Strikethrough   =   0   'False
  181.       EndProperty
  182.       Height          =   255
  183.       Left            =   75
  184.       TabIndex        =   3
  185.       Top             =   1650
  186.       Width           =   1815
  187.    End
  188.    Begin VB.Label Label3 
  189.       Caption         =   "Window Caption:"
  190.       BeginProperty Font 
  191.          Name            =   "Verdana"
  192.          Size            =   9
  193.          Charset         =   0
  194.          Weight          =   400
  195.          Underline       =   0   'False
  196.          Italic          =   0   'False
  197.          Strikethrough   =   0   'False
  198.       EndProperty
  199.       Height          =   255
  200.       Left            =   75
  201.       TabIndex        =   2
  202.       Top             =   1170
  203.       Width           =   1815
  204.    End
  205.    Begin VB.Label Label2 
  206.       Caption         =   "Window Class:"
  207.       BeginProperty Font 
  208.          Name            =   "Verdana"
  209.          Size            =   9
  210.          Charset         =   0
  211.          Weight          =   400
  212.          Underline       =   0   'False
  213.          Italic          =   0   'False
  214.          Strikethrough   =   0   'False
  215.       EndProperty
  216.       Height          =   255
  217.       Left            =   75
  218.       TabIndex        =   1
  219.       Top             =   690
  220.       Width           =   1815
  221.    End
  222.    Begin VB.Label Label1 
  223.       Caption         =   "Window Handle:"
  224.       BeginProperty Font 
  225.          Name            =   "Verdana"
  226.          Size            =   9
  227.          Charset         =   0
  228.          Weight          =   400
  229.          Underline       =   0   'False
  230.          Italic          =   0   'False
  231.          Strikethrough   =   0   'False
  232.       EndProperty
  233.       Height          =   255
  234.       Left            =   75
  235.       TabIndex        =   0
  236.       Top             =   210
  237.       Width           =   1815
  238.    End
  239. Attribute VB_Name = "Form1"
  240. Attribute VB_GlobalNameSpace = False
  241. Attribute VB_Creatable = False
  242. Attribute VB_PredeclaredId = True
  243. Attribute VB_Exposed = False
  244. '  ******************************
  245. '  ******************************
  246. '  ** MASTERING VB6            **
  247. '  ** by Evangelos Petroutos   **
  248. '  ** SYBEX, 1998              **
  249. '  ******************************
  250. '  ******************************
  251. Option Explicit
  252. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  253.     ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
  254.     ByVal cy As Long, ByVal wFlags As Long) As Long
  255. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  256. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
  257.     ByVal yPoint As Long) As Long
  258. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  259. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
  260.     (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  261. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
  262.     (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  263. Const HWND_TOPMOST = -1
  264. Const SWP_SHOWWINDOW = &H40
  265. Private Type POINTAPI
  266.         X As Long
  267.         Y As Long
  268. End Type
  269. Private gStop As Boolean
  270. Private Sub Command1_Click()
  271. Dim mousePT As POINTAPI
  272. Dim prevWindow As Long, curWindow As Long
  273. Dim X As Long, Y As Long
  274. Dim tmpStr As String
  275. Dim retValue As Long
  276. Dim parentWnd As Long
  277.     'Track mouse here
  278.     If Command1.Caption = "Start" Then
  279.         Command1.Caption = "Stop"
  280.         gStop = False
  281.         prevWindow = 0
  282.         'Track until user stops
  283.         Do
  284.             'Stop tracking
  285.             If gStop = True Then Exit Do
  286.             Call GetCursorPos(mousePT)
  287.             X = mousePT.X
  288.             Y = mousePT.Y
  289.             'Get window under mouse
  290.             curWindow = WindowFromPoint(X, Y)
  291.             If curWindow <> prevWindow Then
  292.                 tmpStr = String$(256, " ")
  293.                 prevWindow = curWindow
  294.                 retValue = GetClassName(curWindow, tmpStr, 255)
  295.                 tmpStr = Left$(tmpStr, InStr(tmpStr, vbNullChar) - 1)
  296.                 Text1(0).Text = curWindow
  297.                 Text1(1).Text = tmpStr
  298.                 retValue = GetWindowText(curWindow, tmpStr, 255)
  299.                 Text1(2).Text = tmpStr
  300.                 'Get parent window
  301.                 parentWnd = GetParent(curWindow)
  302.                 retValue = GetClassName(parentWnd, tmpStr, 255)
  303.                 'tmpStr = Left$(tmpStr, InStr(tmpStr, vbNullChar) - 1)
  304.                 Text1(3).Text = parentWnd
  305.                 Text1(4).Text = tmpStr
  306.                 retValue = GetWindowText(parentWnd, tmpStr, 255)
  307.                 Text1(5).Text = tmpStr
  308.             End If
  309.             DoEvents
  310.         Loop
  311.     'Stop tracking the mouse
  312.     Else
  313.         Command1.Caption = "Start"
  314.         gStop = True
  315.     End If
  316. End Sub
  317. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  318.     gStop = True
  319. End Sub
  320. Private Sub Form_Load()
  321. Dim retValue As Long
  322.     If Command1.Caption = "Start" Then
  323.         gStop = False
  324.         retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, _
  325.                                 345, 280, SWP_SHOWWINDOW)
  326.     Else
  327.         gStop = True
  328.         Command1.Caption = "Start"
  329.     End If
  330. End Sub
  331.