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
|
#if !defined(AFX_CTPLCTRL_H__0E380150_021B_4DC2_BBFF_F4EF17DCC038__INCLUDED_)
#define AFX_CTPLCTRL_H__0E380150_021B_4DC2_BBFF_F4EF17DCC038__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// include
/////////////////////////////////////////////////////////////////////////////
// Classe Template attributs couleurs
template <class GENERIC_CTRLCOLOR>
class CTplCtrl2 : public GENERIC_CTRLCOLOR
{
// Construction
public:
CTplCtrl2()
{
m_arClrCtlText[0]=::GetSysColor(COLOR_WINDOWTEXT);
m_arClrCtlText[1]=RGB(0 ,0 ,255); // LtBlue
m_arClrCtlText[2]=RGB(128,0,0); // Red.
m_arClrCtlBkText[0]=::GetSysColor(COLOR_WINDOW);
m_arClrCtlBkText[1]=::GetSysColor(COLOR_WINDOW);
m_arClrCtlBkText[2]=::GetSysColor(COLOR_WINDOW);
for(int i=0;i<3;i++)
m_arHbrClrCtlBk[i]=::CreateSolidBrush(m_arClrCtlBkText[i]);
}
enum ModeColor
{
Normal,
Disable,
ReadOnly
};
void SetBkColor(COLORREF clrCtlBk = RGB(192, 192, 192), // couleur de fond
COLORREF clrCtlText = RGB(0, 0, 0), // couleur d'écriture.
ModeColor eMode=Normal) // mode actif/Inactif/lecture seule.
{
m_arClrCtlText[eMode]=clrCtlText;
m_arClrCtlBkText[eMode]=clrCtlBk;
if(m_arHbrClrCtlBk[eMode])
::DeleteObject(m_arHbrClrCtlBk[eMode]);
m_arHbrClrCtlBk[eMode] = ::CreateSolidBrush(clrCtlBk);
if(m_hWnd) Invalidate();
}
// Attributes
public:
HBRUSH m_arHbrClrCtlBk[3]; // brush de fond
COLORREF m_arClrCtlBkText[3];// couleur du fond.
COLORREF m_arClrCtlText[3]; // couleurs d'ecriture.
// Operations
public:
virtual ~CTplCtrl2()
{
for(int i=0;i<3;i++)
if(m_arHbrClrCtlBk[i]) ::DeleteObject(m_arHbrClrCtlBk[i]);
};
HBRUSH CtlColor(CDC* pDC, UINT nCtlColor)
{
bool bCEdit=(IsKindOf(RUNTIME_CLASS(CEdit))?true:false);
HBRUSH hbr=NULL;
ModeColor eMode=Normal;
if(GetStyle() & ES_READONLY) eMode=ReadOnly;
if(!IsWindowEnabled()) eMode=Disable;
// TODO: Change any attributes of the DC here
pDC->SetTextColor(m_arClrCtlText[eMode]);
// Fixe le fond en transparent pour le texte
if(!bCEdit) pDC->SetBkMode(TRANSPARENT);
else pDC->SetBkColor(m_arClrCtlBkText[eMode]);
// retourne le handle de la brush pour le fond si il existe.
if(m_arHbrClrCtlBk[eMode]) hbr = m_arHbrClrCtlBk[eMode];
// TODO: Return a different brush if the default is not desired
return hbr;
}
virtual BOOL OnChildNotify( UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult )
{
// interception du message reflect
if(message >= WM_CTLCOLORMSGBOX && message <= WM_CTLCOLORSTATIC)
{
UINT nCtlType = message - WM_CTLCOLORMSGBOX;
ASSERT(nCtlType >= CTLCOLOR_MSGBOX);
ASSERT(nCtlType <= CTLCOLOR_STATIC);
CDC dcTemp; dcTemp.m_hDC = (HDC)wParam;
HBRUSH hbr = CtlColor(&dcTemp, nCtlType);
// fast detach of temporary objects
dcTemp.m_hDC = NULL;
*pLResult = (LRESULT)hbr;
return TRUE;
}
return GENERIC_CTRLCOLOR::OnChildNotify( message,wParam, lParam,pLResult );
}
};
#endif |
Partager