• 0

C++: Mouse Hover Function?


Question

I wanted to know if there is a function in C++, that is called on if your mouse hovers over something, and how to use it?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

C++ doesn't include the notion of a mouse. It would be easier if you told us the platform you are working on.

For Windows, it would look something like this:

BOOL bIsFirstMouseMove = FALSE;

WndProc(......)
switch(msg)
{
   case WM_MOUSEMOVE:
      if(bIsFirstMouseMove)
      {
           TRACKMOUSEVENT tme = {......};
           TrackMouseEvent(&tme);
           OnMouseEnter(); // your handler
           bIsFirstMouseMove = FALSE;
       }
   break;
  
  case WM_MOUSELEAVE:
       OnMouseLeave(); // your handler
       bIsFirstMouseMove = TRUE;
  break;
}

Link to comment
Share on other sites

  • 0

C++ what? Borland VCL, MFC, WinAPI or an API on some other platform?

There are Windows Messages WM_MOUSEMOVE (you should also be able to use WM_MOUSEHOVER) and WM_MOUSELEAVE you can respond to to detect when the mouse enters and leaves the client area of a Window (control).

edit: yea, just like the post above

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.