there is no "exposes" mousemove event for this control in vb6. Yeah, i know, annoying. You can use subclassing, but i don't think that it would be any more elegant than your current solution, although it may be more "proper". Personally the only time i personally needed to do this, i ended up creating a fake combo box out of other controls.
Besides subclassing you can determine whether or not cursor is over combo using timer and few api:
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 100 '1/10 of a second
End Sub
Private Sub Timer1_Timer()
'==================================
Dim Rec As RECT, Point As POINTAPI
GetWindowRect Combo1.hwnd, Rec
GetCursorPos Point
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
'MousePointer is over Combobox
Else
'MousePointer is outside Combobox
End If
End Sub
Who said you need a separate timer for each combo?!
One is enough - get position and size (basically rectangle) for each combo (this can be done when you load your form) and perhaps populate array of RECT type.
When timer fires check where cursor is and compare against your combos rect.
What else could be more simple? I posted for you everything you need so all you have to do is expand it a bit.
Besides subclassing you can determine whether or not cursor is over combo using timer and few api:
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 100 '1/10 of a second
End Sub
Private Sub Timer1_Timer()
'==================================
Dim Rec As RECT, Point As POINTAPI
GetWindowRect Combo1.hwnd, Rec
GetCursorPos Point
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
'MousePointer is over Combobox
Else
'MousePointer is outside Combobox
End If
End Sub
especially since vb6 only lets you have 10 in your project that actually work.
I have never used an array so would not know where to start but
This seems to be working fine
Code:
Private Sub Timer11_Timer()
'==================================
Dim Rec As RECT, Point As POINTAPI
GetWindowRect Combo1.hwnd, Rec
GetCursorPos Point
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
'MousePointer is over Combo1
End If
GetWindowRect Combo24.hwnd, Rec
GetCursorPos Point
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
'MousePointer is over Combo24
End If
End Sub
I think Lord Orwell meant to say "10 timers...".
Anyway, VB6 allows much more than 10 - back in VB3 days we could have up to 15 on a single form but even 10 could (but not necessary) give you a headach.
Since VB4 32 bit I haven't encounter any issues what so ever - at least I don't recall anything major (if there was something then it was most definitely my fault of some kind).