Results 1 to 12 of 12

Thread: [RESOLVED] Combox MouseMove Event?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Resolved [RESOLVED] Combox MouseMove Event?

    Is there any way of triggering a mousemove event for a combox

    I have done it using a transparent label but it is not the most elegant way of doing things and is wasteful of resources but its best I can do

    Any ideas

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Combox MouseMove Event?

    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Combox MouseMove Event?

    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: Combox MouseMove Event?

    Thanks for your help gentlemen but given I have 20 combo's on the form I think 20 timers may cause me more problems than 20 labels

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] Combox MouseMove Event?

    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.

    Regards.

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Combox MouseMove Event?

    Quote Originally Posted by RhinoBull
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Arrow Re: [RESOLVED] Combox MouseMove Event?

    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
    As ever THANK YOU Mr RhinoBull

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: [RESOLVED] Combox MouseMove Event?

    LORD Orwell

    You say "especially since vb6 only lets you have 10 in your project that actually work."


    What do you mean

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] Combox MouseMove Event?

    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).

  10. #10

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: [RESOLVED] Combox MouseMove Event?

    Brillant , many thanks for taking the time to create this example.

    Mr RhinoBull, you are the "MAN"

  12. #12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width