3

I need to display some shapes (5 rectangles to be precise) on my caption less child window when ever my cursor is on the window, and erase them when cursor leaves the window; i.e enters into the parent window region.

I am tracking the mouse movement to the child window through NCHITTEST, and the rectangles pop up perfectly. But i cant get them to disappear when my cursor leaves the child window, they just remain there on the client area until WM_PAINT is called on to the window.

Can anybody tell me how to achieve this functionality? I need to use the NCHITTEST case as rest of my functionality depends on it. I have tried tracking mouse_move and lbuttondown events, but these events aren't being captured along with nchittest.

Sundus Alamovic
  • 322
  • 2
  • 18
  • If you are not getting WM_MOUSEMOVE messages then you have a bigger problem. You'll need to find out what window has captured the mouse. Use Spy++ if you have no idea. – Hans Passant Apr 25 '12 at 11:11
  • Thanks for pointing me towards spy++. I see that I am getting the mouse events on my child window, except instead of WM_MOUSEMOVE, I get WM_NCMOUSEMOVE. And moving my cursor over the child window, I am getting WM_NCMOUSELEAVE events. Can anybody tell me what's happening here? – Sundus Alamovic May 07 '12 at 07:55

1 Answers1

1

Look at the TrackMouseEvent() function.

This needs to be called when the mouse enters the window (WM_MOUSEMOVE if it's not already being tracked) and will notify your window when the mouse leaves (WM_MOUSELEAVE).

Here's some sample VB6 code but the should be easily convertable to any other language.

Select Case Msg
    Case WM_MOUSEMOVE
      If Not MouseInWindow Then
        Dim ET As TRACKMOUSEEVENTTYPE
        'Set up the mouse leave notification
        ET.cbSize = Len(ET)
        ET.hwndTrack = Me.hWnd
        ET.dwFlags = TME_HOVER Or TME_LEAVE
        ET.dwHoverTime = 0
        TrackMouseEvent ET

        MouseInWindow = True
        'The mouse has just entered
        Redraw
      End If

    Case WM_MOUSELEAVE
      If MouseInWindow Then
        MouseInWindow = False
        'The mouse has just left
        Redraw
      End If
End Select
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • Is there any other way? I have looked at TrackMouseEvent() and dont get how i should use it, I am not getting the correct mouse events.. One solution that comes to my mind is to explicitly repaint the entire child window after a resizing/moving. But it would still show me resize points when NCHITTEST is called. I am really stuck over here. – Sundus Alamovic May 07 '12 at 07:57
  • It's not hard, but I can only provide VB6 code. You call TrackMouseEvent in the first `WM_MOUSEMOVE` message, and then handle `WM_MOUSELEAVE`. – Deanna May 08 '12 at 09:41
  • but im using NCHITTEST for tracking mouse drag/move. Not individually catering a mouse drag/move event through LButtonDown/LButtonUp and Move event..I'l try out this scheme too though. – Sundus Alamovic May 10 '12 at 04:39
  • i tried this scheme before, it seemed a bit tedious and I had to keep track of a few variables in order to identify my mouse events, using the event handler WM_NCHITTEST seemed simple and cleaned up my code. Thats why i have been looking around to fix the problem within my current implementation. I implemented TrackMouseEvent() in my current implementation, but it didn't help me much. – Sundus Alamovic May 14 '12 at 11:05