自绘CTabCtrl类可以改变背景色(VC)
2008-08-01 10:40
357 查看
#if !defined(AFX_TABCTRLST_H__032460F5_8D49_4AB4_A7BF_1350F7EBE8C2__INCLUDED_)
#define AFX_TABCTRLST_H__032460F5_8D49_4AB4_A7BF_1350F7EBE8C2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TabCtrlST.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST window
class CTabCtrlST : public CTabCtrl
{
// Construction
public:
CTabCtrlST();
// Attributes
public:
//改变背景色
void SetTabBk(COLORREF crColor);
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTabCtrlST)
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTabCtrlST();
// Generated message map functions
protected:
//{{AFX_MSG(CTabCtrlST)
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_MSG
COLORREF m_colorBK;
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TABCTRLST_H__032460F5_8D49_4AB4_A7BF_1350F7EBE8C2__INCLUDED_)
// TabCtrlST.cpp : implementation file
//
#include "stdafx.h"
#include "TabCtrlST.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST
CTabCtrlST::CTabCtrlST()
{
m_colorBK=RGB(240,240,255);
}
CTabCtrlST::~CTabCtrlST()
{
}
BEGIN_MESSAGE_MAP(CTabCtrlST, CTabCtrl)
//{{AFX_MSG_MAP(CTabCtrlST)
ON_WM_DRAWITEM()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST message handlers
void CTabCtrlST::SetTabBk(COLORREF crColor)
{
m_colorBK = crColor;
this->Invalidate();
}
void CTabCtrlST::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
TRACE("nIDCtl:%d/n",nIDCtl);
CTabCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
void CTabCtrlST::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CBrush brushBK(m_colorBK);
char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush;
cbr = &brushBK;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
// TRACE("item:%d/n",lpDrawItemStruct->itemID);
memset(szTabText, '/0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;
GetItem(lpDrawItemStruct->itemID, &tci);
FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,*cbr);
::SetBkColor(lpDrawItemStruct->hDC,bkColor);
TextOut(lpDrawItemStruct->hDC,
lpDrawItemStruct->rcItem.left+5,
lpDrawItemStruct->rcItem.top+5,
tci.pszText,
lstrlen(tci.pszText));
}
BOOL CTabCtrlST::OnEraseBkgnd(CDC* pDC)
{
CBrush brushBK(m_colorBK);
CRect rect;
this->GetClientRect(rect);
pDC->FillRect(rect,&brushBK);
TRACE("%d,%d,%d,%d/n",rect.left,rect.top,rect.right,rect.bottom);
return TRUE;
}
#define AFX_TABCTRLST_H__032460F5_8D49_4AB4_A7BF_1350F7EBE8C2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TabCtrlST.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST window
class CTabCtrlST : public CTabCtrl
{
// Construction
public:
CTabCtrlST();
// Attributes
public:
//改变背景色
void SetTabBk(COLORREF crColor);
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTabCtrlST)
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTabCtrlST();
// Generated message map functions
protected:
//{{AFX_MSG(CTabCtrlST)
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_MSG
COLORREF m_colorBK;
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TABCTRLST_H__032460F5_8D49_4AB4_A7BF_1350F7EBE8C2__INCLUDED_)
// TabCtrlST.cpp : implementation file
//
#include "stdafx.h"
#include "TabCtrlST.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST
CTabCtrlST::CTabCtrlST()
{
m_colorBK=RGB(240,240,255);
}
CTabCtrlST::~CTabCtrlST()
{
}
BEGIN_MESSAGE_MAP(CTabCtrlST, CTabCtrl)
//{{AFX_MSG_MAP(CTabCtrlST)
ON_WM_DRAWITEM()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabCtrlST message handlers
void CTabCtrlST::SetTabBk(COLORREF crColor)
{
m_colorBK = crColor;
this->Invalidate();
}
void CTabCtrlST::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
TRACE("nIDCtl:%d/n",nIDCtl);
CTabCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
void CTabCtrlST::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CBrush brushBK(m_colorBK);
char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush;
cbr = &brushBK;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
// TRACE("item:%d/n",lpDrawItemStruct->itemID);
memset(szTabText, '/0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;
GetItem(lpDrawItemStruct->itemID, &tci);
FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,*cbr);
::SetBkColor(lpDrawItemStruct->hDC,bkColor);
TextOut(lpDrawItemStruct->hDC,
lpDrawItemStruct->rcItem.left+5,
lpDrawItemStruct->rcItem.top+5,
tci.pszText,
lstrlen(tci.pszText));
}
BOOL CTabCtrlST::OnEraseBkgnd(CDC* pDC)
{
CBrush brushBK(m_colorBK);
CRect rect;
this->GetClientRect(rect);
pDC->FillRect(rect,&brushBK);
TRACE("%d,%d,%d,%d/n",rect.left,rect.top,rect.right,rect.bottom);
return TRUE;
}
相关文章推荐
- 自绘CTabCtrl类可以改变背景色(VC)
- 改变CButton背景颜色(自绘CButton)---VC (转)
- vc中改变对话框的背景色(MFC)
- 如何在VC中改变控件的背景色
- 改变CButton背景颜色(自绘CButton)---VC
- VC++改变对话框的背景色和VC++制作伸展自如、收缩随意的对话框
- VC中怎样改变TAB背景色和背景图片
- 如何在VC中改变控件的背景色
- VC 改变edit控件背景色
- 一个继承于CButton的按钮控件类,实现Button背景色与文字的共存与改变,可以自行设计背景色
- VC中改变对话框的背景色(转)
- (转)VC 改变对话框的背景色
- VC++ 中改变对话框及相关控件的背景色(MFC)
- VC中改变对话框的背景色(转)
- 一个继承于CButton的按钮控件类,实现Button背景色与文字的共存与改变,可以自行设计背景色
- VC 改变对话框的背景色
- VC中改变对话框背景色的多种方法
- VC改变对话框的背景色的方法(4种)
- VC改变DialogBar的背景色
- VC++ 中改变对话框及相关控件的背景色(MFC)