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
Solved

get windows handle under mouse pointer vb.net

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…

856 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