Is there a way to find the hWnd of a label control?

I want to detect mouse overs, and when the mouse is no longer over my label, I need to know that too. The problem is, the only way I know to do that is with the SetCapture and ReleaseCapture which binds the mouse to a given control using the hWnd. But a label has no exposed hWnd... So how can I get the hWnd if it isn't exposed?
LVL 3
schworakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
The GetCursorPos API will tell you where the mouse is..

Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Type POINTAPI
        x As Long
        y As Long
End Type
0
schworakAuthor Commented:
Yes, but it won't tell me when the mouse moves off of a control as an event. Using the capture call, the mouse move event is triggered even if I am off of the control.
0
AnswerTheManCommented:
it may be a little clumsy, but it's offhand, and if you'll give it a final touch it will work perfect :

suppose the Given Label is 'Label1'.
add a PictureBox with no picture, minimum size, UnVisible to the form.
Add another Label :'lblMsg'

add this code :

Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    If State = 1 Then
        lblMsg = "Mouse left label1"
        Picture1.Drag 0
    End If
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    lblMsg = "Mouse is over label1"
    Picture1.Drag
End Sub


as i said, you only need a final touch to make it perfect.

''reject this if you expect more elegant solution
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

amit_panjwaniCommented:
use this API

 Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos"
             (lpPoint As POINTAPI) As Long
             Type POINTAPI
                     x As Long
                     y As Long
             End Type

Place a Timer on form,

Now Set interval to approx 1000

within Timer's Sub

Put Code for algorithm

Select

Case Mouse_Coordianates = Label Co ordinated

Do MyThing

It works out for me.

Timer keeps on polling for mouse co ordinates and will let u know what to do on mouseovers






0
schworakAuthor Commented:
I would still like to be able to find the hWnd of opjects that don't expose that value by default, but that code works well.

I found a slightly more complex method to solve my current problem but I like the simplicity of this answer.

I added a little code to clean it up a bit. Now it works great.

Private Sub Form_Load()
    Picture1.Height = 1
    Picture1.Width = 1
End Sub

Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    If State = 1 Then
        lblmsg = "Mouse left label1"
        Picture1.Drag 0
    End If
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    lblmsg = "Mouse is over label1"
    Picture1.Left = Label1.Left + X
    Picture1.Top = Label1.Top + Y
    Picture1.Drag
End Sub




Thanks for putting me on the right track.
0
schworakAuthor Commented:
amit_panjwani, the timer idea is great if I wanted to keep polling like that. but I need this to be triggered by an event. The code above works well enough. Really well actually.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.