Results 1 to 9 of 9

Thread: Wm_mouseleave

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    Wm_mouseleave

    Hi

    I subclassed a command button and im trying to capture the WM_MOUSELEAVE message.

    But it doesnt seem to run by through the WndProc


    Anyone know how to use this?

    Thanks

  2. #2
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    No such event exists unfortunately. I take it you are trying
    to respond to an 'Enter' and 'Leave' event... probably to make
    the button look one way when the mouse is over it and another
    when its somewhere else. Probably the simplest way to do this
    is set up a low priority timer that calls WindowFromPoint ()
    repeatedly. When the hWnd from the button is returned you
    can set some flag/event indicating that you have entered the
    button and when the hWnd from something else is returned you
    can set some flag/event indicating that you have left the button.

    -CC

  3. #3
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    mmm.. Another Way???

    Code:
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long 
    Private Declare Function ReleaseCapture Lib "user32" () As Long 
    Private Declare Function GetCapture Lib "user32" () As Long 
    
    'MouseEnter And MouseExit Code
    
    Private Sub Button_MouseMove(Button As Integer, Shift As Integer, X As Single, _
        Y As Single)
        If (X Or Y) < 0 Or (X > Button.Width) Or (Y > Button.Height) Then
            'Your mouse has left the button
            msgbox "mouse Exit"
        ElseIf GetCapture() <> Button.hwnd Then
            SetCapture Button.hwnd
            'This is where your Mouse Enter and all your normal mouse move stuff happens 'eh
        End If
    End Sub
    Yup??
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  4. #4
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Been there. Done that. Unfortunately it is not 100% reliable.
    Just an example:

    * Launch your sample.
    * Launch Notepad.
    * Place both apps windows on top of each other.
    * Bring your sample to the foreground.
    * Put the mouse in the button.
    * ALT-TAB to Notepad.

    Notice that the exit event does not get triggered. There are other
    ways to see this type of behavior even when your sample remains
    the foreground window. One thing that I like to do is set a
    system-wide message hook to trap all mouse motion events.
    When the mouse position changes, you can check the handle
    that it's over and respond accordingly. The downside is that a
    system-wide hook requires the creation of a C-callable DLL. VB
    can't make one of those, but VC, VC++ can. The timer approach
    (although potentailly expensive in CPU time) tends to be fairly
    easy to implement and does not suffer from the limitations of the
    SetCapture () approach.

  5. #5
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    ahh, what tha?

    System wide hook???

    I tend to disagree that a system wide hook would use up a lot of resources AND what's the point of getting EVERY SINGLE mouse message for windows, when reality says that this guys program is more than likely relativley small... Fair enough if it was office or something big and there was a great chance that anyone using the program is going to mostly deal with his interface while the program is running, but seriously...

    I find the timer approach slows down windows also... (keep in mind that Vb can only have 4 timers running at any 1 time, other wise crash-crash.

    Realisticly I find the previous message, the best solution. Sure.. it has a few minor drawbacks, but who's gonna open up notepad and do all that?? :S It's good enough 4 me.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  6. #6
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    It's just a personal ethic I guess. If the app is big or small, I
    try to make the highest quality components as possible. Anyhow,
    I never made any claims about the System-wide hook being
    resource intensive. I did claim that the timer approach could be.

    That's an interesting 4-timer-crash observation you made. I
    never looked into it that far... but I have personally been so
    dissappointed with the standard VB timer that I created one from
    scratch (which load-tested at 20 instances just fine... no crashes
    or anything).

    Anyhow regarding the 'best' solution. Thats something
    Geespot will have to decide for himself.

    -CC

  7. #7
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  8. #8
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Using the EventVB.dll you can do this thus:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.APIFunctions
    4. Dim WithEvents vbWnd As EventVB.ApiWindow
    5.  
    6. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.  
    8. Command1.Caption = "Mouse over"
    9.  
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.  
    14. Set vbLink = New APIFunctions
    15.  
    16. Set vbWnd = New ApiWindow
    17. vbWnd.hWnd = Me.Command1.hWnd
    18. vbWnd.MouseLeaveTracking = True
    19. vbLink.SubclassedWindows.Add vbWnd
    20.  
    21. End Sub
    22.  
    23. Private Sub vbWnd_MouseLeave()
    24.  
    25. Command1.Caption = "Mouse off"
    26.  
    27. End Sub

    The API involved is TrackMouseEvent...

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  9. #9

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    Re: mmm.. Another Way???

    Originally posted by Wak
    Code:
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long 
    Private Declare Function ReleaseCapture Lib "user32" () As Long 
    Private Declare Function GetCapture Lib "user32" () As Long 
    
    'MouseEnter And MouseExit Code
    
    Private Sub Button_MouseMove(Button As Integer, Shift As Integer, X As Single, _
        Y As Single)
        If (X Or Y) < 0 Or (X > Button.Width) Or (Y > Button.Height) Then
            'Your mouse has left the button
            msgbox "mouse Exit"
        ElseIf GetCapture() <> Button.hwnd Then
            SetCapture Button.hwnd
            'This is where your Mouse Enter and all your normal mouse move stuff happens 'eh
        End If
    End Sub
    Yup??

    Thanks everyone, this will do perfect
    im creating a email app and i just want small extras in the ui, and i wanted a mouseleave event so i could highlight certain controls when mouse was over

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