Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing frmMain.vb (17.03 KB)
Option Explicit On
Imports javaSpy.clsWindowObject
Public Class frmMain
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Declare Function CheckMenuItem Lib "user32" (ByVal hMenu As Integer, ByVal wIDCheckItem As Integer, ByVal wCheck As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Integer) As Integer
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Private Declare Function ShellAbout Lib "shell32" Alias "ShellAboutA" (ByVal hWnd As Integer, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Integer) As Integer
Private Const MF_STRING = &H0&
Private Const MF_SEPARATOR = &H800&
Private Const MF_CHECKED = &H8&
Private Const MF_UNCHECKED = &H0&
Private Const mnuAbout = 5000
Private Const mnuAlwaysOnTop = 5001
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Short
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Short) As Short
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Integer, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Integer, ByVal id As Integer) As Integer
Private Const WM_HOTKEY = &H312
Private Const WM_SYSCOMMAND = &H112
Private Const MOD_CONTROL = &H2
Private Const KEY_F12 = 123
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const LVM_FIRST = &H1000
Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
Private Const LVS_EX_ONECLICKACTIVATE = &H40
Private Const LVS_EX_UNDERLINEHOT = &H800
Private _atomCaptureKey As Integer = 0
Private _infoText As String = ""
Private _capturedWindow As clsWindowObject = Nothing
Private _alwaysOnTop As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_HOTKEY Then
If m.WParam = _atomCaptureKey Then
_capturedWindow = New clsWindowObject(Control.MousePosition)
If Not (_capturedWindow Is Nothing) Then
If Not (_capturedWindow.AssemblyName = Application.ProductName Or _
_capturedWindow.AssemblyName = Application.ProductName + ".vshost") Then
UnregisterHotKey(Me.Handle.ToInt32, _atomCaptureKey)
timerSpy.Tag = False
btnUnload.Enabled = True
btnClick.Enabled = True
btnSettings.Enabled = True
btnMenuSpy.Enabled = _capturedWindow.HasMenu
btnProperties.Enabled = True
lblStatus.Text = "Captured Window :: " + FormatHandle(_capturedWindow.hWnd)
timerSpy.Stop()
Else
_capturedWindow = Nothing
End If
End If
End If
ElseIf m.Msg = WM_SYSCOMMAND Then
If m.WParam = mnuAbout Then
ShellAbout(m.HWnd, Application.ProductName + " " + _
My.Application.Info.Version.ToString, _
"Developed by JaviteSoft ( www.javitesoft.com )" + _
vbCrLf + "Portions include Be.HexEditor from Bernhard Elbl", _
Me.Icon.Handle.ToInt32)
ElseIf m.WParam = mnuAlwaysOnTop Then
_alwaysOnTop = Not _alwaysOnTop
Dim thisWindow As New clsWindowObject(Me.Handle)
thisWindow.AlwaysOnTop = _alwaysOnTop
If _alwaysOnTop Then
CheckMenuItem(GetSystemMenu(m.HWnd, False), mnuAlwaysOnTop, MF_CHECKED)
Else
CheckMenuItem(GetSystemMenu(m.HWnd, False), mnuAlwaysOnTop, MF_UNCHECKED)
End If
DrawMenuBar(m.HWnd)
End If
End If
End Sub
Private Sub LV_UnderlineHot(ByVal ListViewObj As ListView, Optional ByVal bUnderlineHot As Boolean = True)
Dim hWnd As Integer = ListViewObj.Handle.ToInt32
If bUnderlineHot Then
SendMessageLong(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, SendMessageLong(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&) Or LVS_EX_ONECLICKACTIVATE)
SendMessageLong(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, SendMessageLong(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&) Or LVS_EX_UNDERLINEHOT)
Else
SendMessageLong(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, SendMessageLong(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&) And Not LVS_EX_ONECLICKACTIVATE)
SendMessageLong(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, SendMessageLong(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&) And Not LVS_EX_UNDERLINEHOT)
End If
End Sub
Private Sub _showWaitCursor(ByVal bShow As Boolean)
' show/hide the hourglass
If bShow Then
Me.Cursor = Cursors.WaitCursor
Me.UseWaitCursor = True
Else
Me.UseWaitCursor = False
Me.Cursor = Cursors.Arrow
End If
End Sub
Private Sub timerSpy_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerSpy.Tick
Dim thisWindow As New clsWindowObject(Control.MousePosition)
If Not (thisWindow Is Nothing) Then
If thisWindow.AssemblyName = Application.ProductName Or _
thisWindow.AssemblyName = Application.ProductName + ".vshost" Then
txtInfo.Text = "Move the mouse away from this window to begin."
Else
txtInfo.Text = String.Format(_infoText, _
"&H" + Hex(thisWindow.hWnd) + " :: " + _
FormatHandle(thisWindow.hWnd) + " :: " + _
thisWindow.hWnd.ToString, _
"&H" + Hex(thisWindow.hWndParent) + " :: " + _
FormatHandle(thisWindow.hWndParent) + " :: " + _
thisWindow.hWndParent.ToString, _
thisWindow.ClassName, _
thisWindow.Text, _
thisWindow.Left.ToString + ", " + thisWindow.Top.ToString + _
" ( " + thisWindow.Width.ToString + "x" + thisWindow.Height.ToString + " )", _
thisWindow.WindowState, _
thisWindow.AssemblyName)
If btnCapture.Tag Then
Static lastWindow As clsWindowObject = Nothing
If Not (lastWindow Is Nothing) AndAlso _
thisWindow.hWnd <> lastWindow.hWnd Then
lastWindow.InvertBorder()
thisWindow.InvertBorder()
End If
lastWindow = thisWindow
End If
End If
Else
txtInfo.Text = ""
End If
End Sub
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If btnCapture.Tag Then btnCapture.PerformClick()
GlobalDeleteAtom(_atomCaptureKey)
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
_infoText = GetResourceString("txtInfo")
_atomCaptureKey = GlobalAddAtom("Capture Hotkey")
btnCapture.Tag = False
timerSpy.Tag = False
Dim sysMenuHwnd As Integer = GetSystemMenu(Me.Handle.ToInt32, False)
AppendMenu(sysMenuHwnd, MF_SEPARATOR, 0&, vbNullString)
AppendMenu(sysMenuHwnd, MF_STRING, mnuAlwaysOnTop, "Always On Top")
AppendMenu(sysMenuHwnd, MF_STRING, mnuAbout, "About...")
LV_UnderlineHot(lvMain)
End Sub
Private Sub btnUnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnload.Click
_capturedWindow.Close()
MessageBox.Show("The window has been unloaded.", _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
btnCapture.PerformClick()
End Sub
Private Sub lblCaptured_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapture.Click
If btnCapture.Tag Or Not (_capturedWindow Is Nothing) Then
If timerSpy.Tag Then
UnregisterHotKey(Me.Handle.ToInt32, _atomCaptureKey)
timerSpy.Tag = False
End If
btnUnload.Enabled = False
btnClick.Enabled = False
btnSettings.Enabled = False
btnMenuSpy.Enabled = False
btnProperties.Enabled = False
btnCapture.Tag = False
lblStatus.Text = "Ready"
btnCapture.Image = GetResourceImage("window_capture")
_capturedWindow = Nothing
timerSpy.Start()
Else
RegisterHotKey(Me.Handle.ToInt32, _atomCaptureKey, _
MOD_CONTROL, KEY_F12)
btnCapture.Tag = True
timerSpy.Tag = True
lblStatus.Text = "Capturing... Press CTRL + F12 to capture the hovered window"
btnCapture.Image = GetResourceImage("window_captured")
End If
End Sub
Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick.Click
menuClickBtn.Show(tlsCmd.PointToScreen(New Point(btnClick.Bounds.Right, btnClick.Bounds.Top)))
End Sub
Private Sub mnuClick0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick0.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_DEFAULT)
End Sub
Private Sub mnuClick1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick1.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_LBTN_UP)
End Sub
Private Sub mnuClick2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick2.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_LBTN_DOWN)
End Sub
Private Sub mnuClick3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick3.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_LBTN_DBLCLICK)
End Sub
Private Sub mnuClick4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick4.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_RBTN_UP)
End Sub
Private Sub mnuClick5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick5.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_RBTN_DOWN)
End Sub
Private Sub mnuClick6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClick6.Click
_capturedWindow.ClickButton(ClickButtonMethods.BTN_RBTN_DBLCLICK)
End Sub
Private Sub mnuShowWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShowWindow.Click
_capturedWindow.WindowState = WindowStates.SW_SHOW
End Sub
Private Sub mnuHideWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHideWindow.Click
_capturedWindow.WindowState = WindowStates.SW_HIDE
End Sub
Private Sub mnuRestoreWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRestoreWindow.Click
_capturedWindow.WindowState = WindowStates.SW_RESTORE
End Sub
Private Sub mnuEnableWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnableWindow.Click
_capturedWindow.Enabled = True
End Sub
Private Sub mnuDisableWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDisableWindow.Click
_capturedWindow.Enabled = False
End Sub
Private Sub mnuNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNormal.Click
_capturedWindow.WindowState = WindowStates.SW_NORMAL
End Sub
Private Sub mnuMinimized_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMinimized.Click
_capturedWindow.WindowState = WindowStates.SW_MINIMIZE
End Sub
Private Sub mnuMaximized_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMaximized.Click
_capturedWindow.WindowState = WindowStates.SW_MAXIMIZE
End Sub
Private Sub mnuTopTrue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTopTrue.Click
_capturedWindow.AlwaysOnTop = True
End Sub
Private Sub mnuTopFalse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTopFalse.Click
_capturedWindow.AlwaysOnTop = False
End Sub
Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
menuSettings.Show(tlsCmd.PointToScreen(New Point(btnSettings.Bounds.Right, btnSettings.Bounds.Top)))
End Sub
Private Sub btnProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProperties.Click
_showWaitCursor(True)
With New frmWindowProps(_capturedWindow)
.Show(Me)
End With
_showWaitCursor(False)
End Sub
Private Sub btnMenuSpy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenuSpy.Click
_showWaitCursor(True)
With New frmMenuSpy(_capturedWindow)
.Show(Me)
End With
_showWaitCursor(False)
End Sub
Private Sub lvMain_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvMain.DoubleClick
If lvMain.SelectedItems().Count > 0 Then
_showWaitCursor(True)
Select Case lvMain.SelectedItems(0).ImageKey
Case "window_spy.png"
With New frmWindowSpy(_capturedWindow)
.Show(Me)
End With
Case "process_spy.png"
With New frmProcessSpy(_capturedWindow)
.Show(Me)
End With
Case "dom_spy.png"
Dim domURL As String = ""
If Not (_capturedWindow Is Nothing) AndAlso _
_capturedWindow.IsWindow AndAlso _
_capturedWindow.Text.Contains("://") Then _
domURL = _capturedWindow.Text
With New frmDOMSpy(domURL)
.Show(Me)
End With
Case "ip_spy.png"
With New frmIPSpy
.Show(Me)
End With
Case "wmi_spy.png"
With New frmWMISpy
.Show(Me)
End With
Case "db_spy.png"
With New frmDBSpy
.Show(Me)
End With
Case "net_spy.png"
With New frmNetSpy
.Show(Me)
End With
Case "packet_spy.png"
With New frmPacketSpy
.Show(Me)
End With
End Select
_showWaitCursor(False)
End If
End Sub
Private Sub lvMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lvMain.KeyDown
If e.KeyCode = Keys.Enter Then lvMain_DoubleClick(sender, Nothing)
End Sub
Private Sub menuSettings_Closed(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripDropDownClosedEventArgs) Handles menuSettings.Closed
btnSettings.Checked = False
End Sub
Private Sub menuSettings_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles menuSettings.Opening
btnSettings.Checked = True
End Sub
Private Sub menuClickBtn_Closed(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripDropDownClosedEventArgs) Handles menuClickBtn.Closed
btnClick.Checked = False
End Sub
Private Sub menuClickBtn_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles menuClickBtn.Opening
btnClick.Checked = True
End Sub
End Class