Solved

get windows handle under mouse pointer vb.net

Posted on 2011-09-07
3
1,312 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
ID: 36500558
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36500631
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
ID: 36503341
Works like a charm! Thanks IM ... I was making it much more complicated than it needed to be =)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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