Solved

mouse over bitmap

Posted on 2012-03-11
3
609 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

687 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