Link to home
Start Free TrialLog in
Avatar of Pber
PberFlag for Canada

asked on

SPY++ style application in VB.NET or C#

I building on the sample given to me by Idle_Mind in the related question.  I'm trying to only get it to highlight and display main forms and dialogs and not the controls within a dialog.
i.e.  If I were to spy on wordpad.  I only want to see the main frame, but not the toolbar, ruler or the richtext window.  

Is this possible, if so how?

I presume I would just do a check in the picturebox1_Movemove event and do a check in the following routine:
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pber

ASKER

Thanks.  This is what I got?

    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)
            Dim MainWindow As IntPtr = GetAncestor(handle, GA_ROOT)
 
 
            Label1.Text = MainWindow.ToString("X")
 
            If Not MainWindow.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 MainWindow.Equals(prevHandle) Then
                ' get new rectangle
                GetWindowRect(MainWindow, 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 = MainWindow
        End If
    End Sub

Open in new window

Looks good...does it work?   =)
Avatar of Pber

ASKER

Yeah, it works awesome.  I also added a check to ignore itself:

If MainWindow <> Me.Handle Then
end if
 
Thanks again.
Avatar of Pber

ASKER

Thanks again.
BTW...I like the way you did your profile.   ;)
Avatar of Pber

ASKER

Thanks.  (:
Just noticed a bug.  The Blog enum doesn't compile.  Fixed it with a constant.
(: