?
Solved

mouse over bitmap

Posted on 2012-03-11
3
Medium Priority
?
622 Views
Last Modified: 2012-03-18
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
Comment
Question by:edvinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37710022
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 37710101
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
 
LVL 1

Author Closing Comment

by:edvinson
ID: 37734818
Excellent. Sorry for the delay in awarding points.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question