[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CBitmapButton OnMouseOver

Posted on 2000-04-01
9
Medium Priority
?
1,284 Views
Last Modified: 2013-11-20
Theres an image for each of the four states

MouseUp
MouseDown
Selected
Execute

hence the four differenet Bitmaps u need for CBitmapButton... but how come theres no Bitmap for when the mouse is over the button???

How do i make the CBItmapButton change to the appropriate bitmap OnMouseOVer ???

thanks
0
Comment
Question by:lamer
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 2676635
You can try the following:
Create a CButton class like the following:

Header file:

#if !defined(AFX_BITMAPMOUSEOVERBUTTON_H__0B183F55_B341_4718_8919_408EBB1C6731__INCLUDED_)
#define AFX_BITMAPMOUSEOVERBUTTON_H__0B183F55_B341_4718_8919_408EBB1C6731__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// BitmapMouseOverButton.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CBitmapMouseOverButton window

class CBitmapMouseOverButton : public CBitmapButton
{
// Construction
public:
      CBitmapMouseOverButton();

// Attributes
public:
protected:
      bool HasInitiatedTme;
      TRACKMOUSEEVENT tme;
// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CBitmapMouseOverButton)
      //}}AFX_VIRTUAL

// Implementation
public:
      virtual ~CBitmapMouseOverButton();

      // Generated message map functions
protected:
      //{{AFX_MSG(CBitmapMouseOverButton)
      afx_msg void OnMouseMove(UINT nFlags, CPoint point);
      afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
      //}}AFX_MSG

      DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BITMAPMOUSEOVERBUTTON_H__0B183F55_B341_4718_8919_408EBB1C6731__INCLUDED_)




****************************************
CPP file:
// BitmapMouseOverButton.cpp : implementation file
//

#include "stdafx.h"
#include "Test.h"
#include "BitmapMouseOverButton.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBitmapMouseOverButton

CBitmapMouseOverButton::CBitmapMouseOverButton()
{
      HasInitiatedTme=false;
      LoadBitmaps(IDB_BITMAP1,IDB_BITMAP2,IDB_BITMAP3,IDB_BITMAP4);
}

CBitmapMouseOverButton::~CBitmapMouseOverButton()
{
      tme.cbSize = sizeof(TRACKMOUSEEVENT);
      tme.dwFlags = TME_LEAVE|TME_CANCEL;
      tme.hwndTrack = this->m_hWnd;
      ::_TrackMouseEvent(&tme);
      tme.dwFlags = TME_HOVER|TME_CANCEL;
      tme.hwndTrack = this->m_hWnd;
      ::_TrackMouseEvent(&tme);
}


BEGIN_MESSAGE_MAP(CBitmapMouseOverButton, CBitmapButton)
      //{{AFX_MSG_MAP(CBitmapMouseOverButton)
      ON_WM_MOUSEMOVE()
      ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBitmapMouseOverButton message handlers

void CBitmapMouseOverButton::OnMouseMove(UINT nFlags, CPoint point)
{
      if (!HasInitiatedTme)
      {
            HasInitiatedTme=true;
            LoadBitmaps(IDB_BITMAP5,IDB_BITMAP2,IDB_BITMAP5,IDB_BITMAP5);
            Invalidate(true);
            tme.cbSize = sizeof(TRACKMOUSEEVENT);
            tme.dwFlags = TME_LEAVE;
            tme.hwndTrack = this->m_hWnd;
            ::_TrackMouseEvent(&tme);
      }
      
      CBitmapButton::OnMouseMove(nFlags, point);
}

LRESULT CBitmapMouseOverButton::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
      HasInitiatedTme=false;
      LoadBitmaps(IDB_BITMAP1,IDB_BITMAP2,IDB_BITMAP3,IDB_BITMAP4);
      Invalidate(true);
      return TRUE;
}
0
 

Author Comment

by:lamer
ID: 2677172
err... well, not exactly what i wanted but its ok nontheless....

the thing is, ive been usign a whole bunch of my own derivition of the normal MFC class I was hoping that theres a really easy solution to this..maybe something that ive missed in CBitmapButton.. rather than creating another class derived from CBitmapButton which can handle mousemove and mouseleave...

i was actually afraid that this will be the answer...

thanks anyway, i'll keep this around to see if anyone knows anything else..

regards.
0
 
LVL 30

Accepted Solution

by:
Axter earned 150 total points
ID: 2677200
I really hope some body does give you a better answer, because I would be interested in an easier method myself.
I don't understand why the makers of MFC didn't think to add this feature to CBitmapButton.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 10

Expert Comment

by:RONSLOW
ID: 2678587
Use a toolbar with a single button in it.  This gives you the flat button with mouse-over support.

NOTE: buttons predate mouse support by a long shot.  Adding support for mouseover to the MFC class would need to be done in a way that is transparent to existing code.  If done at all, it would probably be as yet another wrapper for CButton.

PS: I like your code .. I do something similar in my own classes .. only I implement the flat-look for buttons (among other things).
0
 
LVL 30

Expert Comment

by:Axter
ID: 2686128
RONSLOW,
I tried using the Toolbar, but I couldn't get it to work.
Could you please give more information as to how you use if for a mouse-over.
If you have some code, could you please post it.

Thanks.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2686505
I can create a toolbar control on a dialog like this... (where I have a CToolBarCtrl m_toolbar in my dialog class and a ON_COMMAND(IDC_BUTTON,OnButtonPushed)

    m_toolbar.Create(
        WS_VISIBLE | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER,
        CRect(50,50,150,100), this, IDC_BUTTON);
    TBBUTTON button;
    button.iBitmap = NULL;
    button.idCommand = IDC_BUTTON; // command to be sent when button pressed
    button.fsState = TBSTATE_ENABLED; // button state
    button.fsStyle = BTNS_BUTTON | BTNS_SHOWTEXT; // button style
    button.dwData = 0; // application-defined value (unused)
    button.iString = m_toolbar.AddStrings("Button\0"); // zero-based index of button label string
    m_toolbar.SetStyle(
        m_toolbar.GetStyle() | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
    m_toolbar.AddButtons(1,&button);
    m_toolbar.SetBitmapSize(CSize(0,0));

You would need to add to this code to create image lists for the various states and assign them to the toolbareg. m_toolbar.SetHotImageList(&m_hotimagelist);

This should all be wrapped up in a class.

By using a toolbar you get extra options (like mixing text and graphics, flat look etc).

0
 
LVL 30

Expert Comment

by:Axter
ID: 2691855
RONSLOW,
I got your method to work.  Interesting approach.  However, I think for using bitmaps, my class is less complicated.

I was hoping to get your approach to work with the tooltip popping out at the bottom. But I didn't have much success.

Thanks for posting the code.  I'm adding it to my toolbox for future text requirements.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2691876
I might add it myself .. hadn't done that before.

Obviously, one would need to add some pictures etc.  Should be quite powerful when nicely wrapped up in a class.

Also, one could put all ones button images in a single (set of) image list(s) and tell each button which images to use.  Could be very cool.

I think I'll withdraw mine as it sounds like you are going to use Axter's suggestion (unless you want to do some point splitting or wait for another solution)

0
 

Author Comment

by:lamer
ID: 2692790
Guess i'll be using ur codes after all
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 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