Solved

SPY++ style Window finder tool in VB.net

Posted on 2009-05-06
5
1,333 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now