1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// le .h
#if !defined(AFX_BUTTONEX_H__3259688A_1DF5_4CE4_9558_CC399AF94BA6__INCLUDED_)
#define AFX_BUTTONEX_H__3259688A_1DF5_4CE4_9558_CC399AF94BA6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ButtonEx.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CButtonEx window
class CButtonEx : public CButton
{
// Construction
public:
CButtonEx();
// Attributes
public:
// Operations
public:
// changement de couleur du texte du bouton dynamique si possible
void SetTextColor(const COLORREF clrTextColor)
{
m_clrTextColor=clrTextColor;
if(m_hWnd) Invalidate();
}
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CButtonEx)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CButtonEx();
// Generated message map functions
protected:
//{{AFX_MSG(CButtonEx)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private :
COLORREF m_clrTextColor;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BUTTONEX_H__3259688A_1DF5_4CE4_9558_CC399AF94BA6__INCLUDED_)
// le .cpp : ButtonEx.cpp
/////////////////////////////////////////////////////////////////////////////
// CButtonEx
CButtonEx::CButtonEx()
{
m_clrTextColor=RGB(0,0,0); // noir
}
CButtonEx::~CButtonEx()
{
}
BEGIN_MESSAGE_MAP(CButtonEx, CButton)
//{{AFX_MSG_MAP(CButtonEx)
ON_WM_DRAWITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CButtonEx message handlers
void CButtonEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
UINT uStyle = DFCS_BUTTONPUSH;
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
if (lpDrawItemStruct->itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED;
dc.DrawFrameControl(&lpDrawItemStruct->rcItem,DFC_BUTTON, uStyle);
// dession du texte.
CString strText;
GetWindowText(strText);
COLORREF crOldColor = dc.SetTextColor(m_clrTextColor);
dc.DrawText(strText, strText.GetLength(),&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
dc.SetTextColor(crOldColor);
CBrush blkBrush(RGB(0,0,0));
// gestion du marquage du focus.
if (lpDrawItemStruct->itemState & ODS_FOCUS)
{
CRect rct(&(lpDrawItemStruct->rcItem));
dc.FrameRect(rct, &blkBrush);
rct.InflateRect(-3,-3);
dc.DrawFocusRect(rct);
}
}
void CButtonEx::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0, BS_OWNERDRAW );
CButton::PreSubclassWindow();
} |
Partager