| 12
 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
 
 |  
// include
/////////////////////////////////////////////////////////////////////////////
// Classe Template attributs couleurs 
template <class GENERIC_CTRLCOLOR>
class CTplCtrl : public GENERIC_CTRLCOLOR
{
// Construction
public:
    CTplCtrl()
    {
        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'ecriture.
                    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 ~CTplCtrl()
    {
        for(int i=0;i<3;i++) 
        if(m_arHbrClrCtlBk[i]) ::DeleteObject(m_arHbrClrCtlBk[i]);
    };
 
	BOOL OnChildNotify(UINT message, WPARAM wParam,
                               LPARAM lParam, LRESULT* pLResult)
   {
 
      HDC hdcChild = (HDC)wParam;
	  CDC dc;
	  dc.Attach(hdcChild);
      if(pLResult)
	  {
		*pLResult = (LRESULT)CtlColor(&dc, message);
	  }
 
	  dc.Detach();
 
      return TRUE;
   } 
    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;
    }
}; | 
Partager