Solved

get windows handle under mouse pointer vb.net

Posted on 2011-09-07
3
1,275 Views
Last Modified: 2012-05-12
Hey Experts...

Anyone know how to find out the windows handle of an object under the mouse pointer in VB.NET... have found solutions in other languages but no idea how to do this in VB.

I've got a low level hook on the mouse and I'm intercepting the left mouse click... what I need to know is exactly where the mouse was when that click event fired.

Thanks!
0
Comment
Question by:romieb69
3 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
Comment Utility
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Just use the WindowFromPoint() API like this:
Public Class Form1

    Public Structure PointAPI
        Public X As Integer
        Public Y As Integer
        Public Sub New(ByVal pt As Point)
            Me.X = pt.X
            Me.Y = pt.Y
        End Sub
    End Structure

    Public Declare Function WindowFromPoint Lib "user32" (ByVal pt As PointAPI) As IntPtr

    Private Sub Foo()
        ' ... in your callback where you get the left click ...

        Dim curHandle As IntPtr = WindowFromPoint(New PointAPI(Cursor.Position))
        ' ... now use "curHandle" somehow ...
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:romieb69
Comment Utility
Works like a charm! Thanks IM ... I was making it much more complicated than it needed to be =)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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