Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake an ActiveX control that highlights itself when the mouse is over it using WindowFromPointXY
KeywordsActiveX control, highlight, WindowFromPointXY
CategoriesActiveX, ActiveX Controls, Graphics, Multimedia
 
In the control's MouseMove event handler, see if the control is already highlighted. If it is not, highlight it and enable a Timer.

When the Timer's event fires, use the GetCursorPos and WindowFromPointXY API functions to see if the mouse is still over the control. If the mouse has moved off of the control, unhighlight it and disable the Timer.

This works even if the ActiveX has transparent zones, wich can be selected by setting his BackStyle property to "0 - Transparent".

 
Private Sub UserControl_MouseMove(Button As Integer, Shift _
    As Integer, X As Single, Y As Single)
    If highlighted Then Exit Sub
    highlighted = True
    Shape1.FillColor = vbBlue
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim pt As POINTAPI

    ' See where the cursor is.
    GetCursorPos pt
    
    ' Translate into window coordinates.
    If WindowFromPointXY(pt.X, pt.Y) <> UserControl.hWnd _
        Then
        highlighted = False
        Shape1.FillColor = vbRed
        Timer1.Enabled = False
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated