您的位置:首页 > 其它

自绘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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: