Solved

SPY++ style Window finder tool in VB.net

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

11 Experts available now in Live!

Get 1:1 Help Now