Expand|Select|Wrap|Line Numbers
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- 'Api Spy Example by PAT or JK
- 'Webpage: http://www.patorjk.com/
- 'This is just a small example on how to do a drap and drop
- 'api spy.
- Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
- Private Declare Function GetModuleFileName Lib "Kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
- Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
- Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
- Private Declare Function getparent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
- Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
- Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
- Private Declare Function GetActiveWindow Lib "user32" () As Long
- Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
- Private Const SWP_NOMOVE = 2
- Private Const SWP_NOSIZE = 1
- Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
- Private Const HWND_TOPMOST = -1
- Private Const HWND_NOTOPMOST = -2
- Private Type POINTAPI
- x As Long
- Y As Long
- End Type
- Public Sub StayOnTop(Frm As Form)
- Call SetWindowPos(Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
- End Sub
- Function MakeOne(Text As String) As String
- ' this sub just takes all the Chr(13) and Chr(10) out of
- ' the text. I know I could have written a sub that was quicker
- ' using the Instr function, but when I used this it seemed
- ' pretty fast so I just left it this way.
- Dim i As Integer, t$, BadChr(1 To 2) As String
- For i = 1 To Len(Text)
- If Mid$(Text, i, 1) <> Chr$(13) And Mid$(Text, i, 1) <> Chr$(10) Then
- t$ = t$ & Mid$(Text, i, 1)
- End If
- MakeOne = t$
- Next
- End Function
- Private Sub Command1_Click()
- MsgBox "Drag and drop the ring onto the window you want to find the information on.", 32, "PAT or JK"
- End Sub
- Private Sub Command2_Click()
- MsgBox "Example By: PAT or JK" & Chr(13) & "Webpage: http://www.patorjk.com/", 32, "PAT or JK"
- End Sub
- Private Sub Command3_Click()
- End
- End Sub
- Private Sub Form_Load()
- StayOnTop Me 'set form on top
- Picture1.Picture = Picture2.Picture ' give picture1 the ring picture
- End Sub
- Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
- Picture1.Picture = Me.Picture ' set the picture to nothing
- Picture1.MousePointer = 99 ' set the mousepointer to the ring
- End Sub
- Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
- If Button = 1 Then ' if the mouse button is down then
- Call ApiSpyStuff ' spy on the windows
- End If
- End Sub
- Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
- Picture1.MousePointer = 0 ' set the mouse pointer back to normal
- Picture1.Picture = Picture2.Picture ' give picture1 the ring picture
- Call ApiSpyStuff ' get the info from the window
- End Sub
- Sub ApiSpyStuff()
- ' This sub does all the "api spy stuff"
- Dim CursorPos As POINTAPI, WinOver As Long
- Dim WinText As String, Z As Long, WinClassName As String
- Dim WinParent As Long, ParentWindowText As String
- Dim ParentClassName As String
- Static WinPrevious As Long
- ' find where your cursor is
- Call GetCursorPos(CursorPos)
- ' get the x and y points from that position
- WinOver = WindowFromPoint(CursorPos.x, CursorPos.Y)
- ' Make sure the window is a different window
- If WinOver <> WinPrevious Then
- ' set the old window equal to the new window (for next time)
- WinPrevious = WinOver
- ' Window Handle
- Label7.Caption = WinOver
- ' Window Text
- WinText = String(100, Chr(0))
- Z = GetWindowText(WinOver, WinText, 100)
- Label8.Caption = Chr$(34) & MakeOne(Left(WinText, Z)) & Chr$(34)
- ' Window Class Name
- WinClassName = String(100, Chr(0))
- Z = GetClassName(WinOver, WinClassName, 100) ' Window Class
- Label9.Caption = Chr$(34) & Left(WinClassName, Z) & Chr$(34)
- ' Parent Window Handle
- WinParent = getparent(WinOver)
- If WinParent <> 0 Then
- ' Parent window handle
- Label10.Caption = WinParent
- ' Parent Window Text
- ParentWindowText = String(100, Chr(0))
- Z = GetWindowText(WinParent, ParentWindowText, 100)
- Label11.Caption = Chr$(34) & Left(ParentWindowText, Z) & Chr$(34)
- ' Parent Window Class
- ParentClassName = String(100, Chr(0))
- Z = GetClassName(WinParent, ParentClassName, 100)
- Label12.Caption = Chr$(34) & Left(ParentClassName, Z) & Chr$(34)
- Else
- Label10.Caption = "NONE"
- Label11.Caption = "NONE"
- Label12.Caption = "NONE"
- End If
- End If
- End Sub
-- yes, i have tried this, i don't know vb, but have attempted to replicate this in .NET but was a falure.