VB icon

***UPDATED*** Window SPY

Email
Submitted on: 1/1/2015 11:44:00 PM
By: Matt Evans (from psc cd)  
Level: Not Given
User Rating: By 15 Users
Compatibility: VB 5.0, VB 6.0
Views: 3102
 
     ***UPDATED*** Gets tons of information on the window your mouse is over.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :***UPDATED*** Window SPY
'**************************************
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Public Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetClassName& Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
Public Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ***UPDATED*** Window SPY
' Description:***UPDATED*** Gets tons of information on the window your mouse is over.
' By: Matt Evans (from psc cd)
'**************************************

**** Put this in a module ****
Function WindowSPY(WinHdl As TextBox, WinClass As TextBox, WinTxt As TextBox, WinStyle As TextBox, WinIDNum As TextBox, WinPHandle As TextBox, WinPText As TextBox, WinPClass As TextBox, WinModule As TextBox)
'Call This In A Timer
Dim pt32 As POINTAPI, ptx As Long, pty As Long, sWindowText As String * 100
Dim sClassName As String * 100, hWndOver As Long, hWndParent As Long
Dim sParentClassName As String * 100, wID As Long, lWindowStyle As Long
Dim hInstance As Long, sParentWindowText As String * 100
Dim sModuleFileName As String * 100, r As Long
Static hWndLast As Long
Call GetCursorPos(pt32)
ptx = pt32.X
pty = pt32.Y
hWndOver = WindowFromPointXY(ptx, pty)
If hWndOver <> hWndLast Then
hWndLast = hWndOver
WinHdl.Text = "Window Handle: " & hWndOver
r = GetWindowText(hWndOver, sWindowText, 100)
WinTxt.Text = "Window Text: " & Left(sWindowText, r)
r = GetClassName(hWndOver, sClassName, 100)
WinClass.Text = "Window Class Name: " & Left(sClassName, r)
lWindowStyle = GetWindowLong(hWndOver, GWL_STYLE)
WinStyle.Text = "Window Style: " & lWindowStyle
hWndParent = GetParent(hWndOver)
If hWndParent <> 0 Then
wID = GetWindowWord(hWndOver, GWW_ID)
WinIDNum.Text = "Window ID Number: " & wID
WinPHandle.Text = "Parent Window Handle: " & hWndParent
r = GetWindowText(hWndParent, sParentWindowText, 100)
WinPText.Text = "Parent Window Text: " & Left(sParentWindowText, r)
r = GetClassName(hWndParent, sParentClassName, 100)
WinPClass.Text = "Parent Window Class Name: " & Left(sParentClassName, r)
Else
WinIDNum.Text = "Window ID Number: N/A"
WinPHandle.Text = "Parent Window Handle: N/A"
WinPText.Text = "Parent Window Text : N/A"
WinPClass.Text = "Parent Window Class Name: N/A"
End If
hInstance = GetWindowWord(hWndOver, GWW_HINSTANCE)
r = GetModuleFileName(hInstance, sModuleFileName, 100)
WinModule.Text = "Module: " & Left(sModuleFileName, r)
End If
End Function
****** END OF MODULE ******
'Put this is notepad and rename is winspy.frm
VERSION 5.00
Begin VB.Form Form1 
BackColor=&H00000000&
Caption ="Window SPY"
ClientHeight=3480
ClientLeft =2280
ClientTop=1590
ClientWidth =4440
LinkTopic="Form1"
ScaleHeight =3480
ScaleWidth =4440
Begin VB.Timer Timer1 
Interval=10
Left=1080
Top =1560
End
Begin VB.TextBox Text9 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=8
Text="Text9"
Top =3000
Width=4215
End
Begin VB.TextBox Text8 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=7
Text="Text8"
Top =2640
Width=4215
End
Begin VB.TextBox Text7 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=6
Text="Text7"
Top =2280
Width=4215
End
Begin VB.TextBox Text6 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=5
Text="Text6"
Top =1920
Width=4215
End
Begin VB.TextBox Text5 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=4
Text="Text5"
Top =1560
Width=4215
End
Begin VB.TextBox Text4 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=3
Text="Text4"
Top =1200
Width=4215
End
Begin VB.TextBox Text3 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=2
Text="Text3"
Top =840
Width=4215
End
Begin VB.TextBox Text2 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=1
Text="Text2"
Top =480
Width=4215
End
Begin VB.TextBox Text1 
Appearance =0 'Flat
BackColor=&H00000000&
BeginProperty Font 
Name="Arial"
Size=8.25
Charset =0
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
EndProperty
ForeColor=&H00FFFFFF&
Height =285
Left=120
TabIndex=0
Text="Text1"
Top =120
Width=4215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Timer1_Timer()
WindowSPY Text1, Text2, Text3, Text4, Text5, Text6, Text7, Text8, Text9
End Sub


Other 5 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/29/2017 11:52:32 PMEvariste Galois

Although this is harsh, something needs to be said: if you're going to post this much code, put it into a .zip file. I'm not sure I see how much is gained by making anyone who looks at it -- to format it first. In my opinion, anything which is supposed to be complete on this site should be presented in the same way you'd turn in a school assignment or code review...
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.