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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
| #if !defined(AFX_CXTabCtrl_H__A11951B3_2F95_11D3_A896_00A0C9B6FB28__INCLUDED_)
#define AFX_CXTabCtrl_H__A11951B3_2F95_11D3_A896_00A0C9B6FB28__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CXTabCtrl.h : header file
//
template <class GENERIC_DLGCOLOR = CWnd>
class CTplDlgColor : public GENERIC_DLGCOLOR
{
public:
CTplDlgColor(UINT nID=0,CWnd* pParent=NULL) :GENERIC_DLGCOLOR(nID,pParent)
{
/* HBRUSH */ m_HbrClrCtlBk=NULL ;
/* COLORREF */ m_ClrCtlText= RGB(0, 0, 0) ;
}
//---------------------------------------------------------------------------------
~CTplDlgColor()
{
if(m_HbrClrCtlBk) ::DeleteObject(m_HbrClrCtlBk);
}
//---------------------------------------------------------------------------------
void SetDialogBkColor(COLORREF clrCtlBk = RGB(192, 192, 192),
COLORREF clrCtlText = RGB(0, 0, 0) )
{
//m_HbrClrCtlBk est à null dans le constructeur
if(m_HbrClrCtlBk) ::DeleteObject(m_HbrClrCtlBk);
m_HbrClrCtlBk = ::CreateSolidBrush(clrCtlBk);
m_ClrCtlText = clrCtlText;
/* COLORREF */m_ClrCtlBk= clrCtlBk;
}
//---------------------------------------------------------------------------------
HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
if(pWnd->m_hWnd == m_hWnd)
hbr= GENERIC_DLGCOLOR::OnCtlColor(pDC, pWnd, nCtlColor); // for dialogs
else hbr= GENERIC_DLGCOLOR::OnCtlColor(pDC, this, nCtlColor); // send reflect message
/* CTLCOLOR_BTN button control
CTLCOLOR_DLG dialog box
CTLCOLOR_EDIT edit control
CTLCOLOR_LISTBOX list box
CTLCOLOR_MSGBOX message box
CTLCOLOR_SCROLLBAR scroll bar
CTLCOLOR_STATIC static text, frame, or rectangle
*/
// TODO: Change any attributes of the DC here
// par exemple en fonction de nCtlColor voir doc.
switch(nCtlColor)
{
// Intercepte le message pour la dialogue et les statics.
case CTLCOLOR_DLG:
case CTLCOLOR_STATIC :
// Fixe la couleur decriture du texte
pDC->SetTextColor(m_ClrCtlText);
// enventuellement suivant les cas
// pDC->pDC->SetBkColor(m_ClrCtlBk);
// Fixe le fond en transparent pour le texte
// à ne pas faire pour un edit.
pDC->SetBkMode(TRANSPARENT);
// retourne le handle de la brush pour le fond si il existe.
if(m_HbrClrCtlBk ) hbr = m_HbrClrCtlBk;
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
//---------------------------------------------------------------------------------
virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if(message==WM_CTLCOLOR)
{
_AFX_CTLCOLOR* pCtl = (_AFX_CTLCOLOR*)lParam;
CDC dcTemp; dcTemp.m_hDC = pCtl->hDC;
CWnd wndTemp; wndTemp.m_hWnd = pCtl->hWnd;
UINT nCtlType = pCtl->nCtlType;
HBRUSH hbr = OnCtlColor(&dcTemp, &wndTemp, nCtlType);
// fast detach of temporary objects
dcTemp.m_hDC = NULL;
wndTemp.m_hWnd = NULL;
*pResult = (LRESULT)hbr;
return TRUE;
}
return GENERIC_DLGCOLOR::OnWndMsg(message, wParam, lParam, pResult);
}
//---------------------------------------------------------------------------------
private:
struct _AFX_CTLCOLOR
{
HWND hWnd;
HDC hDC;
UINT nCtlType;
};
HBRUSH m_HbrClrCtlBk;
COLORREF m_ClrCtlText;
COLORREF m_ClrCtlBk;
};
/////////////////////////////////////////////////////////////////////////////
// CXTabCtrl window
#include <afxtempl.h>
class CXTabCtrl : public CTabCtrl
{
// Construction
public:
DECLARE_DYNAMIC(CXTabCtrl)
CXTabCtrl();
// Attributes
public:
BOOL m_bAutoPannelSize;
COLORREF m_crBackColor;
BOOL m_bFirstBackColor;
// Operations
public:
void AddTab(CWnd* pWnd, LPTSTR lpszCaption, int iImage =0);
void EnableTab(int iIndex, BOOL bEnable = TRUE);
BOOL SelectTab(int iIndex);
void DeleteAllTabs();
void DeleteTab(int iIndex);
void SetTopLeftCorner(CPoint pt);
BOOL IsTabEnabled(int iIndex);
void SetDisabledColor(COLORREF cr);
void SetSelectedColor(COLORREF cr);
void SetNormalColor(COLORREF cr);
void SetMouseOverColor(COLORREF cr);
void SetAutoSizePannel(BOOL bEnable=TRUE){m_bAutoPannelSize=bEnable;}
// fixe la couleur de fond de la fenêtre
void SetBackGroundColor(COLORREF cBackColor);
// fixe la couleur du bouton d'onglet non selectionné
void SetNoSelBackGroundColor(COLORREF cBackColor);
void ReSizeCurPannel();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CXTabCtrl)
protected:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CXTabCtrl();
// Generated message map functions
protected:
CArray<BOOL, BOOL> m_arrayStatusTab; //** enabled Y\N
int m_iSelectedTab;
POINT m_ptTabs;
COLORREF m_crSelected;
COLORREF m_crDisabled;
COLORREF m_crNormal;
COLORREF m_crMouseOver;
COLORREF m_crNoBackColor;
int m_iIndexMouseOver;
bool m_bMouseOver;
bool m_bColorMouseOver;
bool m_bColorNormal;
bool m_bColorDisabled;
bool m_bColorSelected;
bool m_bInit;
//{{AFX_MSG(CXTabCtrl)
afx_msg BOOL OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg BOOL OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CXTabCtrl_H__A11951B3_2F95_11D3_A896_00A0C9B6FB28__INCLUDED_) |
Partager