Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Detecting mouse move over a CBitmapButton

Posted on 1999-07-12
13
Medium Priority
?
452 Views
Last Modified: 2013-11-20
I'd like to set up my program so that when the user places the mouse over my button, the bitmap changes.  I've tried using the OnMouseMove function from my dialog, but it's detecting the wm_mousemove message everywhere but the button.  Has anyone done this before?  Please help!  Thanks!!
0
Comment
Question by:Sandym
[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
  • 3
  • 2
  • +5
13 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1309660
Hi!
You can derive class from CButton and handle OnMouseMove method (it is a simplest way).
0
 
LVL 1

Expert Comment

by:hbuehler
ID: 1309661
Don't forget SetCapture() or you may loose the mouse
leaving your window.

- hans
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1309662
The mouse move message will usually go to the window that the mouse is over. Therefore you shouldn't use OnMouseMove for the dialog, but instead for the button. So you will need to derive a class from CBitmapButton and catch OnMouseMove there.

To clarify, any window can call SetCapture to continue receiving mouse messages even when the mouse is not over the window. In your case, though, you do not need this functionality.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:Sandym
ID: 1309663
I suppose I wasn't clear enough in my post.  Here's more details:
I don't have a seperate class for the button and doing so would require a lot of code changes.  
My button is a CBitmapButton that is located on a dialog window along with several other controls.  I have tried using the setCapture function, and it works wonderfully for the mousemove event, but renders the rest of my controls, the system menu, and all hotkeys useless..

Anyone have any suggestions now that i've properly stated my problem?
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1309664
i agree with thui , u have to subclass your button in order to get its messages.

doi a derived class from CBitmapButton, and subclass it in the Dialog OnInitDialog function.
0
 
LVL 2

Expert Comment

by:cpopin
ID: 1309665
Thui is right, you derive and subclass.  You wont have to rewrite anything.  The following line placed in OnInitDialog() will do the subclassing:

    m_stcInfo.SubclassDlgItem(IDC_INFO, this);

where m_stcInfo is the member variable and IDC_INFO is the resource id.
0
 

Author Comment

by:Sandym
ID: 1309666
I've added that line into the OnInitDialog() and it's still not sending any wm_mousemove messages to the main window.  What else do I need to do?

By the way, thanks so much for everyone who's helping me!
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1309667
dear sadym.
i'll give you a brief explenation about sub class and its use:
sub class is when u have a dialog for instance , this dialog has controls, those control are actully classes, but you are using them as control, it means u are using just their derived class function in other words, every control derived from CWnd to get all the functionality of that class you have to sub class it do the following?:

go to Inser->NewClass, now give a new name to your class, and in the derived combobox choose CBitmapButton.
click OK, now this class is added to your project.
in your dialog cpp file add this:
#include "newclass.h"  // the class you just added" h file

now in the dialog OnInitDialog do this:
mNewClass.SubclassDlgItem(IDC_MYBUTTON, this);

mNewClass is object of the new class you added (remmember ?)
and IDC_MYBUTTON is the Button resource name.

now compile and link.

now every message of that button will direct to this new class you added, in that class you have to create message map for every message you want to catch using classwizard.

hope that help

don't hesitate to ask, this is what this site for :-)

good luck


0
 
LVL 4

Accepted Solution

by:
pagladasu earned 200 total points
ID: 1309668
You can override the PreTranslateMessage() and capture the WM_MOUSEMOVE message. Try something like this:
      BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
      {
      // TODO: Add your specialized code here and/or call the base class
      if(pMsg->message==WM_MOUSEMOVE){
      CWnd *pwnd=GetDlgItem(IDC_PICBUTTON);
      CRect rect;
      CPoint pt=pMsg->pt;
      pwnd->GetWindowRect(&rect);
      rect.NormalizeRect();
      if(rect.PtInRect(pt)){
            //write your code to change the bitmap
      }
      }
      return CDialog::PreTranslateMessage(pMsg);
      }
Hope this helps.
Thanks
pagladasu
0
 

Expert Comment

by:ashman061699
ID: 1309669
Have a look to the MSJ, issue 10/1998.
Paul DiLascia wrote an excellent article about exactly that thing that you want to do.  You even can get the source of TrackMouseEvent (thats like he called the example app) under
http://www.microsoft.com/msj/1098/code/oct98cqa.zip,
 the text you should find under
http://www.microsoft.com/msj/backissuestop.htm

0
 

Author Comment

by:Sandym
ID: 1309670
That is what I had in the first place pagladasu.. and the button was not sending a WM_MOUSE message to catch.  I ended up doing the whole derive and subclass and adding to the OnInitDialog as Shay detailed.  It still wasn't working, so I used Spy++ to see that the button was sending a WM_SETCURSOR with a mouse message of WM_MOUSEMOVE.  I then used the OnSetCursor function and checked to see what the last parameter was.  If it matched up, I then post a message with WM_MOUSEMOVE.  This message then goes to my OnMouseMove function with a point of (0,0).  I know that if I have that point, that i'm on top of the button and to change the state of the button to focused so that the bitmap changed.  Anywhere else and I put the state back to normal.  I know it's not pretty, but it works and after 3 days of working on it, I'm happy!

Thanks for everyone's help
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1309671
by the way Sandym you welcome...
0
 
LVL 2

Expert Comment

by:cpopin
ID: 1309672
Ashman,
More accutely, the URL for TrackMouseEvent is:
http://www.microsoft.com/msj/1098/c++/c++1098top.htm
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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