Solved

get windows handle under mouse pointer vb.net

Posted on 2011-09-07
3
1,363 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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.
Progress
Starting up a Project

688 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