Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

Window Spy

Browsing MainForm.frm (22.38 KB)

VERSION 5.00
Begin VB.Form MainForm 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Window Spy"
   ClientHeight    =   4215
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6855
   Icon            =   "MainForm.frx":0000
   MaxButton       =   0   'False
   ScaleHeight     =   4215
   ScaleWidth      =   6855
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer HotKeyCheckerTimer 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   0
      Top             =   720
   End
   Begin VB.Timer KeyCheckerTimer 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   0
      Top             =   360
   End
   Begin VB.Timer WindowInfoTimer 
      Interval        =   150
      Left            =   0
      Top             =   0
   End
   Begin VB.Frame Frame3 
      Caption         =   "Window Spy Console"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   975
      Left            =   120
      TabIndex        =   12
      Top             =   3120
      Width           =   6615
      Begin VB.CommandButton Command8 
         Caption         =   "E&xit"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   4920
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   360
         Width           =   1455
      End
      Begin VB.CommandButton Command7 
         Caption         =   "&Advanced..."
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1800
         Style           =   1  'Graphical
         TabIndex        =   1
         ToolTipText     =   "Show Advanced Window Spy"
         Top             =   360
         Width           =   1455
      End
      Begin VB.CommandButton Command6 
         Caption         =   "&Process Spy..."
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3360
         Style           =   1  'Graphical
         TabIndex        =   2
         ToolTipText     =   "Show Process Spy"
         Top             =   360
         Width           =   1455
      End
      Begin VB.CommandButton Command5 
         Caption         =   "&Capture Window"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   0
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Window Commands"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2895
      Left            =   4800
      TabIndex        =   11
      Top             =   120
      Width           =   1935
      Begin VB.CommandButton Command9 
         Caption         =   "&Menu Spy..."
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   8
         ToolTipText     =   "Spy on the menus of the captured window"
         Top             =   1800
         Width           =   1455
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Properties"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   9
         ToolTipText     =   "Window Properties"
         Top             =   2280
         Width           =   1455
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Window &Settings"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   7
         ToolTipText     =   "Change settings for the captured object or window"
         Top             =   1320
         Width           =   1455
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Click &Button..."
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   6
         ToolTipText     =   "Send a mouse click to the captured object or window"
         Top             =   840
         Width           =   1455
      End
      Begin VB.CommandButton Command1 
         Caption         =   "&Unload Window"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         Style           =   1  'Graphical
         TabIndex        =   5
         ToolTipText     =   "Unload the captured object or window"
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Window Information"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2895
      Left            =   120
      TabIndex        =   10
      Top             =   120
      Width           =   4575
      Begin VB.TextBox Text1 
         BackColor       =   &H00C0C0C0&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2535
         Left            =   120
         Locked          =   -1  'True
         MultiLine       =   -1  'True
         TabIndex        =   4
         Top             =   240
         Width           =   4335
      End
   End
   Begin VB.Menu wsPopupMenu 
      Caption         =   "wsPopupMenu"
      Visible         =   0   'False
      Begin VB.Menu ShowWindowMenu 
         Caption         =   "&Show Window"
      End
      Begin VB.Menu HideWindowMenu 
         Caption         =   "&Hide Window"
      End
      Begin VB.Menu RestoreWindowMenu 
         Caption         =   "&Restore Window"
      End
      Begin VB.Menu Blank1 
         Caption         =   "-"
      End
      Begin VB.Menu EnableWindowMenu 
         Caption         =   "&Enable Window"
      End
      Begin VB.Menu DisableWindowMenu 
         Caption         =   "&Disable Window"
      End
      Begin VB.Menu Blank2 
         Caption         =   "-"
      End
      Begin VB.Menu SetWSMenu 
         Caption         =   "Set &Window State"
         Begin VB.Menu NormalWSMenu 
            Caption         =   "&Normal"
         End
         Begin VB.Menu MinimizedWSMenu 
            Caption         =   "&Minimized"
         End
         Begin VB.Menu MaximizedWSMenu 
            Caption         =   "M&aximized"
         End
      End
      Begin VB.Menu Blank3 
         Caption         =   "-"
      End
      Begin VB.Menu SetWOTMenu 
         Caption         =   "Set Window &On Top"
         Begin VB.Menu WOTTrueMenu 
            Caption         =   "&True"
         End
         Begin VB.Menu WOTFalseMenu 
            Caption         =   "&False"
         End
      End
   End
   Begin VB.Menu ClickButtonPopupMenu 
      Caption         =   "ClickButtonPopupMenu"
      Visible         =   0   'False
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&0  Default Method"
         Index           =   0
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&1  Left Button Down"
         Index           =   1
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&2  Left Button Up"
         Index           =   2
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&3  Left Button Dbl Click"
         Index           =   3
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&4  Right Button Down"
         Index           =   4
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&5  Right Button Up"
         Index           =   5
      End
      Begin VB.Menu ClickMethodMenu 
         Caption         =   "&6  Right Button Dbl Click"
         Index           =   6
      End
   End
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Ver As String
Dim AlwaysOnTopMenuChecked As Boolean
Dim UseHotKeysMenuChecked As Boolean
Dim CapturedWindow As Long
Dim LastWindow As Long
Dim HKShow As Boolean
Dim HKEnable As Boolean

Dim Timer_WindowInfo As Boolean
Dim Timer_KeyChecker As Boolean
Dim Timer_HotKeyChecker As Boolean

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const KS_KEYDOWN = &H8001

Private Const KEY_F1 = 112
Private Const KEY_F2 = 113
Private Const KEY_F3 = 114
Private Const KEY_F4 = 115
Private Const KEY_F5 = 116
Private Const KEY_F6 = 117
Private Const KEY_F7 = 118
Private Const KEY_F8 = 119
Private Const KEY_F9 = 120
Private Const KEY_F10 = 121
Private Const KEY_F11 = 122
Private Const KEY_F12 = 123

Sub AboutMenu_Click()
MsgBox "                 Window Spy v" & Ver & vbCrLf & vbCrLf & _
"           Captured Window Hot Keys:" & vbCrLf & vbCrLf & _
"           F9 - Unload Window/Object" & vbCrLf & _
"                  F10 - Click Button" & vbCrLf & _
"       F11 - Show/Hide Window/Object" & vbCrLf & _
"     F12 - Enable/Disable Window/Object" & vbCrLf & vbCrLf & _
"                  Created by Jason" & vbCrLf & _
"Contact me at jasonspc69@hotmail.com" & vbCrLf & vbCrLf & _
"    � 1999 - 2000 Jason's PC Software", vbOKOnly, "About Window Spy"
End Sub


Sub AlwaysOnTopMenu_Click()
AlwaysOnTopMenuChecked = Not AlwaysOnTopMenuChecked
If AlwaysOnTopMenuChecked Then
CheckMenuItem GetSystemMenu(hWnd, False), AlwaysOnTopMenuID, MF_CHECKED
Else
CheckMenuItem GetSystemMenu(hWnd, False), AlwaysOnTopMenuID, MF_UNCHECKED
End If
WindowOnTop hWnd, AlwaysOnTopMenuChecked
End Sub

Sub EnableControls(bOption As Boolean)
Command1.Enabled = bOption
Command2.Enabled = bOption
Command3.Enabled = bOption
Command4.Enabled = bOption
Command9.Enabled = bOption
WindowInfoTimer.Enabled = Not bOption
End Sub


Sub EnableTimers(bOption As Boolean)
If bOption Then
WindowInfoTimer.Enabled = Timer_WindowInfo
KeyCheckerTimer.Enabled = Timer_KeyChecker
HotKeyCheckerTimer.Enabled = Timer_HotKeyChecker
Else
Timer_WindowInfo = WindowInfoTimer.Enabled
Timer_KeyChecker = KeyCheckerTimer.Enabled
Timer_HotKeyChecker = HotKeyCheckerTimer.Enabled
WindowInfoTimer.Enabled = False
KeyCheckerTimer.Enabled = False
HotKeyCheckerTimer.Enabled = False
End If
End Sub

Function GetAOTValue() As Boolean
    GetAOTValue = AlwaysOnTopMenuChecked
End Function

Sub UseHotKeysMenu_Click()
UseHotKeysMenuChecked = Not UseHotKeysMenuChecked
If UseHotKeysMenuChecked Then
CheckMenuItem GetSystemMenu(hWnd, False), UseHotKeysMenuID, MF_CHECKED
Else
CheckMenuItem GetSystemMenu(hWnd, False), UseHotKeysMenuID, MF_UNCHECKED
End If
If CapturedWindow Then HotKeyCheckerTimer.Enabled = UseHotKeysMenuChecked
End Sub

Sub WindowCaptured()
On Error Resume Next
CapturedWindow = LastWindow
EnableControls True
If MenuExists(CapturedWindow) > 0 Then
Command9.Enabled = True
Else
Command9.Enabled = False
End If
HKShow = True
HKEnable = True
KeyCheckerTimer.Enabled = False
HotKeyCheckerTimer.Enabled = UseHotKeysMenuChecked
Caption = App.Title + " - Window Captured"
Command5.Caption = "&Release Window"
If WindowState <> 0 Then WindowState = 0
Command1.SetFocus
End Sub

Private Sub ClickMethodMenu_Click(Index As Integer)
    ClickButton CapturedWindow, Index
End Sub

Private Sub Command1_Click()
    If CloseWindow(CapturedWindow) Then
        MsgBox "The window was unloaded successfully.", vbExclamation
        Command5_Click
    Else
        MsgBox "An error occurred while trying to unload the window.", vbExclamation
    End If
End Sub

Private Sub Command2_Click()
    PopupMenu ClickButtonPopupMenu, , Frame2.Left + Command2.Left + Command2.Width, Frame2.Top + Command2.Top, ClickMethodMenu(0)
End Sub

Private Sub Command3_Click()
    PopupMenu wsPopupMenu, , Frame2.Left + Command3.Left + Command3.Width, Frame2.Top + Command3.Top
End Sub

Private Sub Command4_Click()
    If AlwaysOnTopMenuChecked Then WindowOnTop WindowPropForm.hWnd, True
    WindowPropForm.SetHandle CapturedWindow
    EnableTimers False
    WindowPropForm.Show 1
    EnableTimers True
End Sub

Private Sub Command5_Click()
    If Command5.Caption = "&Capture Window" Then
        MsgBox "Move the mouse over the window or object you want to capture and press F12", vbExclamation
        Caption = App.Title + " - Capturing Window..."
        Command5.Caption = "Cancel"
        Command7.Enabled = False
        Command6.Enabled = False
        KeyCheckerTimer.Enabled = True
    ElseIf Command5.Caption = "&Release Window" Then
        On Error Resume Next
        Caption = App.Title
        EnableControls False
        CapturedWindow = 0
        HotKeyCheckerTimer.Enabled = False
        Command7.Enabled = True
        Command6.Enabled = True
        Command5.Caption = "&Capture Window"
    ElseIf Command5.Caption = "Cancel" Then
        Caption = App.Title
        Command5.Caption = "&Capture Window"
        Command7.Enabled = True
        Command6.Enabled = True
        KeyCheckerTimer.Enabled = False
    End If
End Sub


Private Sub Command6_Click()
    EnableTimers False
    If AlwaysOnTopMenuChecked Then WindowOnTop ProcessSpyForm.hWnd, True
    ProcessSpyForm.Show 1
    EnableTimers True
End Sub

Private Sub Command7_Click()
    EnableTimers False
    If AlwaysOnTopMenuChecked Then WindowOnTop EnumWindowsForm.hWnd, True
    EnumWindowsForm.Show 1
    EnableTimers True
End Sub

Private Sub Command8_Click()
    Unload Me
End Sub

Private Sub Command9_Click()
    If AlwaysOnTopMenuChecked Then WindowOnTop EnumMenusForm.hWnd, True
        EnumMenusForm.Set_hWnd CapturedWindow
        EnumMenusForm.Tree.Nodes.Clear
        MenuSpy_BuildTree MenuExists(CapturedWindow), EnumMenusForm.Tree
        If EnumMenusForm.Tree.Nodes.Count = 0 Then
        Unload EnumMenusForm
        MsgBox "No menu items found on the captured window", vbExclamation, "Menu Spy"
    Else
        EnableTimers False
        EnumMenusForm.Show 1
        EnableTimers True
    End If
End Sub

Private Sub DisableWindowMenu_Click()
WindowEnabled CapturedWindow, False
End Sub

Private Sub EnableWindowMenu_Click()
WindowEnabled CapturedWindow, True
End Sub

Private Sub Form_Load()
    Ver = App.Major & "." & App.Minor & _
    IIf(App.Revision = 0, "", "." & App.Revision)
    CButtonAll Me
    EnableControls False
    WindowOnTop hWnd, True
    AlwaysOnTopMenuChecked = True
    UseHotKeysMenuChecked = True
    AppendMenu GetSystemMenu(hWnd, False), MF_SEPARATOR, 0&, vbNullString
    AppendMenu GetSystemMenu(hWnd, False), MF_STRING Or MF_CHECKED, AlwaysOnTopMenuID, "Always On Top"
    AppendMenu GetSystemMenu(hWnd, False), MF_STRING Or MF_CHECKED, UseHotKeysMenuID, "Use Hot Keys"
    AppendMenu GetSystemMenu(hWnd, False), MF_SEPARATOR, 0&, vbNullString
    AppendMenu GetSystemMenu(hWnd, False), MF_STRING, AboutMenuID, "About..."
    SetWindowStyle Frame1.hWnd, GetWindowStyle(Frame1.hWnd) Or BS_CENTER
    SetWindowStyle Frame2.hWnd, GetWindowStyle(Frame2.hWnd) Or BS_CENTER
    SetWindowStyle Frame3.hWnd, GetWindowStyle(Frame3.hWnd) Or BS_CENTER
    StartSysMenuSubClass hWnd
End Sub


Private Sub Form_Unload(Cancel As Integer)
    EndSysMenuSubClass
    End
End Sub


Private Sub HideWindowMenu_Click()
SetWindowState CapturedWindow, SW_HIDE
End Sub

Private Sub HotKeyCheckerTimer_Timer()
    If GetAsyncKeyState(KEY_F9) = KS_KEYDOWN Then
        Command1_Click
    End If
    If GetAsyncKeyState(KEY_F10) = KS_KEYDOWN Then
        Command2_Click
    End If
    If GetAsyncKeyState(KEY_F11) = KS_KEYDOWN Then
        HKShow = Not HKShow
        If HKShow Then
            SetWindowState CapturedWindow, SW_SHOW
        Else
            SetWindowState CapturedWindow, SW_HIDE
        End If
    End If
    If GetAsyncKeyState(KEY_F12) = KS_KEYDOWN Then
        HKEnable = Not HKEnable
        WindowEnabled CapturedWindow, HKEnable
    End If
End Sub

Private Sub KeyCheckerTimer_Timer()
    If GetAsyncKeyState(KEY_F12) = KS_KEYDOWN Then
        DrawWindowBorder LastWindow
        WindowCaptured
    End If
End Sub

Private Sub MaximizedWSMenu_Click()
SetWindowState CapturedWindow, SW_MAXIMIZE
End Sub

Private Sub MinimizedWSMenu_Click()
SetWindowState CapturedWindow, SW_MINIMIZE
End Sub

Private Sub NormalWSMenu_Click()
SetWindowState CapturedWindow, SW_NORMAL
End Sub

Private Sub RestoreWindowMenu_Click()
SetWindowState CapturedWindow, SW_RESTORE
End Sub

Private Sub ShowWindowMenu_Click()
SetWindowState CapturedWindow, SW_SHOW
End Sub

Private Sub WindowInfoTimer_Timer()
    On Error Resume Next
    Dim WindowInfo As WINDOW_INFO
    WindowInfo = GetWindowInfo()
    If LastWindow = WindowInfo.hWnd Then Exit Sub
    If KeyCheckerTimer.Enabled Then DrawWindowBorder WindowInfo.hWnd
    Text1.Text = "Window Handle: &H" & Hex(WindowInfo.hWnd)
    Text1.Text = Text1.Text & vbCrLf & "Parent Window Handle: " & IIf(WindowInfo.Parent_hWnd = 0, "N/A", "&H" & Hex(WindowInfo.Parent_hWnd))
    Text1.Text = Text1.Text & vbCrLf & "Window Caption: " & WindowInfo.WindowCaption
    Text1.Text = Text1.Text & vbCrLf & "Window Width: " & (WindowInfo.WindowRECT.Right - WindowInfo.WindowRECT.Left)
    Text1.Text = Text1.Text & vbCrLf & "Window Height: " & (WindowInfo.WindowRECT.Bottom - WindowInfo.WindowRECT.Top)
    Select Case WindowInfo.WindowState
    Case 0
    Text1.Text = Text1.Text & vbCrLf & "Window is neither maximized or minimized."
    Case 1
    Text1.Text = Text1.Text & vbCrLf & "Window is Minimized."
    Case 2
    Text1.Text = Text1.Text & vbCrLf & "Window is Maximized."
    End Select
    If WindowInfo.WindowEnabled Then
        Text1.Text = Text1.Text & vbCrLf & "Window is Enabled."
        Else
        Text1.Text = Text1.Text & vbCrLf & "Window is Disabled."
    End If
    Text1.Text = Text1.Text & vbCrLf & "Class Name: " & Trim(WindowInfo.ClassName)
    If UCase(Trim(WindowInfo.ModuleFilename)) = UCase(IIf(Right(App.Path, 1) <> "\", App.Path + "\", App.Path) & App.EXEName) & ".EXE" Then WindowInfo.ModuleFilename = ""
    'Text1.Text = Text1.Text & vbCrLf & "Module Filename: " & Trim(WindowInfo.ModuleFilename)
    Text1.Text = Text1.Text & vbCrLf & "Executable Path: " & Trim(WindowInfo.EXEPath)
    LastWindow = WindowInfo.hWnd
End Sub


Private Sub WOTFalseMenu_Click()
WindowOnTop CapturedWindow, False
End Sub

Private Sub WOTTrueMenu_Click()
WindowOnTop CapturedWindow, True
End Sub


Download MainForm.frm

Back to file list


Back to project page