Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mouse over bitmap

Posted on 2012-03-11
3
Medium Priority
?
634 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

Independent Software Vendors: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

636 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