Solved

get windows handle under mouse pointer vb.net

Posted on 2011-09-07
3
1,344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36500558
0
 
LVL 86

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …

726 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