Solved

SPY++ style Window finder tool in VB.net

Posted on 2009-05-06
5
1,366 Views
Last Modified: 2012-05-06
I need a Windows Finder SPY++ type program in VB.NET.  All I need is the ablity for my app for drag a SPY++ type Windows Finder target over another Window to grab the handle of that window.

I've founds lots of examples mainly in C++  (even vb6) and I just don't want to convert to .NET if I don't have to re-invent the wheel.

Does anyone know of a VB.NET version of the Window finder in SPY++?  version
0
Comment
Question by:Pber
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24318995
what about Managed Spy? Give it a try: http://msdn.microsoft.com/en-us/magazine/cc163617.aspx
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24320009
Simple example....  (not perfect)

Add a PictureBox and a Label to a new Form:
Public Class Form1
 
    Private prevHandle As IntPtr
    Private prevRC As Rect
 
    Public Structure PointAPI
 
        Public X As Integer
        Public Y As Integer
 
        Public Sub New(ByVal x As Integer, ByVal y As Integer)
            Me.X = x
            Me.Y = y
        End Sub
 
    End Structure
 
    Public Structure Rect
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure
 
    Public Declare Function WindowFromPoint Lib "user32" (ByVal pt As PointAPI) As IntPtr
    Public Declare Function GetWindowRect Lib "user32" (ByVal handle As IntPtr, ByRef lpRect As Rect) As Integer
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.BorderStyle = BorderStyle.FixedSingle
        PictureBox1.BackColor = Color.Red
        PictureBox1.Cursor = Cursors.Cross
    End Sub
 
    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        MessageBox.Show("Drag the PictureBox around the screen...")
    End Sub
 
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            prevHandle = IntPtr.Zero
        End If
    End Sub
 
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim pt As New PointAPI(Cursor.Position.X, Cursor.Position.Y)
            Dim handle As IntPtr = WindowFromPoint(pt)
 
            Label1.Text = handle.ToString("X")
 
            If Not handle.Equals(prevHandle) AndAlso Not prevHandle.Equals(IntPtr.Zero) Then
                ' erase previous rectanlge
                ControlPaint.DrawReversibleFrame(New Rectangle(prevRC.Left, prevRC.Top, prevRC.Right - prevRC.Left, prevRC.Bottom - prevRC.Top), Color.Black, FrameStyle.Thick)
            End If
 
            If Not handle.Equals(prevHandle) Then
                ' get new rectangle
                GetWindowRect(handle, prevRC)
 
                ' draw new rectangle
                ControlPaint.DrawReversibleFrame(New Rectangle(prevRC.Left, prevRC.Top, prevRC.Right - prevRC.Left, prevRC.Bottom - prevRC.Top), Color.Black, FrameStyle.Thick)
            End If
 
            ' store new handle
            prevHandle = handle
        End If
    End Sub
 
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ControlPaint.DrawReversibleFrame(New Rectangle(prevRC.Left, prevRC.Top, prevRC.Right - prevRC.Left, prevRC.Bottom - prevRC.Top), Color.Black, FrameStyle.Thick)
        End If
    End Sub
 
End Class

Open in new window

0
 
LVL 26

Author Closing Comment

by:Pber
ID: 31578691
Exactly what I was looking for.
0
 
LVL 39

Expert Comment

by:abel
ID: 24324662
(i'm not the OP) That was a very concise and clean example of a rather complex subject, nice work, Idle!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24326089
I've written similar apps before for other questions here on EE...  =)
(I will say, though, it's a LOT easier in .Net than VB6!)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question