Solved

mouse over bitmap

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now