• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

mouse over bitmap

I have successfully figured out a simple subclass on an edit box, via my previous question.

Now , what I really want to know is..

I have a bitmap, in my app ( BM_MYLOGO )

and I would like to know , simply, if the user has hovered over this resource for more than 3 seconds.

This is my ultimate goal, for the last few questions I have asked.

Slowly I am getting close, but nope.

Thanks.
0
edvinson
Asked:
edvinson
1 Solution
 
alexey_gusevCommented:
0
 
jkrCommented:
You could use 'TrackMouseEvent()' (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646265%28v=vs.85%29.aspx) for that purpose or it's equivalent in Win32 code. E.g.

void StartTrackMouseEvent(HWND hwnd) {

  TRACKMOUSEEVENT tme;

  ZeroMemory(&tme,sizeof(tme));

  tme.cbSize = sizeof(tme);
  tme.dwFlafgs = TME_MOUSEHOVER;
  tme.hwndTrack = hwnd;
  tme.dwHoverTime = 3000; // 3s

  TrackMouseEvent(&tme);
}

// inside your 'WndProc()':

    case WM_HOVER: {

     // check if that was inside your bitmap:

       int nX = LOWORD(lParam);
       int nY = HIWORD(lParam);

       RECT rc; // fill that with the bounding rectangle of your bitmap

       POINT pt = { nX, nY};

      if (PtInRect(&pt,&rc)) {

         // Action, hover event happened over your bitmap
      }
    }
    

Open in new window


The equivalent - a 'roll your own' version of 'TrackMouseEvent()' would be

#define TID_POLLMOUSE 100
#define MOUSE_POLL_DELAY 500

  case WM_MOUSEMOVE:
    SetTimer(hwnd,TID_POLLMOUSE,MOUSE_POLL_DELAY,NULL);
    break;
  case WM_TIMER:
    RECT rc;
    POINT pt;
    GetWindowRect(hwnd,&rc);
    GetCursorPos(&pt);
    if(PtInRect(&rc,pt))
    {
      PostMessage(hwnd,WM_MOUSEHOVER,0,0L);
      break;
    }
    PostMessage(hwnd,WM_MOUSELEAVE,0,0L);
    KillTimer(hwnd,TID_POLLMOUSE);
    break;

Open in new window


(Code taken from http://www.codeproject.com/Articles/359/Capturing-the-Mouse - "Capturing the Mouse")
0
 
edvinsonAuthor Commented:
Excellent. Sorry for the delay in awarding points.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now