lamer
asked on
CBitmapButton OnMouseOver
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
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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).
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.
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.
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,OnBu ttonPushed )
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("Butt on\0"); // zero-based index of button label string
m_toolbar.SetStyle(
m_toolbar.GetStyle() | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
m_toolbar.AddButtons(1,&bu tton);
m_toolbar.SetBitmapSize(CS ize(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_hotimag elist);
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).
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("Butt
m_toolbar.SetStyle(
m_toolbar.GetStyle() | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
m_toolbar.AddButtons(1,&bu
m_toolbar.SetBitmapSize(CS
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(
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).
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.
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.
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)
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)
ASKER
Guess i'll be using ur codes after all
Create a CButton class like the following:
Header file:
#if !defined(AFX_BITMAPMOUSEOV
#define AFX_BITMAPMOUSEOVERBUTTON_
#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(CBitmapMou
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CBitmapMouseOverButton();
// Generated message map functions
protected:
//{{AFX_MSG(CBitmapMouseOv
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_BITMAPMOUSEOV
**************************
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::CB
{
HasInitiatedTme=false;
LoadBitmaps(IDB_BITMAP1,ID
}
CBitmapMouseOverButton::~C
{
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(CBitmapM
//{{AFX_MSG_MAP(CBitmapMou
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// CBitmapMouseOverButton message handlers
void CBitmapMouseOverButton::On
{
if (!HasInitiatedTme)
{
HasInitiatedTme=true;
LoadBitmaps(IDB_BITMAP5,ID
Invalidate(true);
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = this->m_hWnd;
::_TrackMouseEvent(&tme);
}
CBitmapButton::OnMouseMove
}
LRESULT CBitmapMouseOverButton::On
{
HasInitiatedTme=false;
LoadBitmaps(IDB_BITMAP1,ID
Invalidate(true);
return TRUE;
}