关于TabCtrl,请各位指教。高分奉送……

alfwolf 2001-11-28 04:29:17
如何改变背景(颜色或者添加图象),如何改变字体颜色……我继承了一个CTabCtrl类。是不是在BOOL CMyTabCtrl::OnEraseBkgnd(CDC* pDC) 中实现?最好给出代码实例!谢谢了先。
...全文
164 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
turbopeng 2002-01-23
  • 打赏
  • 举报
回复
grvu
alfwolf 2001-12-03
  • 打赏
  • 举报
回复
那么我想加入图标应该如何来做呢?
alfwolf 2001-12-03
  • 打赏
  • 举报
回复
谢谢masterz()大哥。
分数全部给你吧,那两个兄弟我另外给吧!
可否留下email,以后好向大哥学习!
masterz 2001-12-03
  • 打赏
  • 举报
回复
void CMyTab::DrawItem( LPDRAWITEMSTRUCT lpdis )
{
char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush;
if(lpdis->itemID%2)
{
cbr = &m_brRed;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
}
else
{
cbr = &m_brBlue;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
}
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;

GetItem(lpdis->itemID, &tci);
FillRect(lpdis->hDC,&lpdis->rcItem,*cbr);
::SetBkColor(lpdis->hDC,bkColor);
HICON hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDR_MAINFRAME));
DrawIcon(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,hicon);//DrawIconEx is more useful
DeleteObject(hicon);
TextOut(lpdis->hDC,
lpdis->rcItem.left+32,//leave room for icon width
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));

}
alfwolf 2001-12-03
  • 打赏
  • 举报
回复
请问我该如何想其中加入图标呢?各位帮帮忙,很着急!!!
分数还可以增加!
masterz 2001-11-28
  • 打赏
  • 举报
回复
m_brRed定义成CMyDialogDlg的成员呀
alfwolf 2001-11-28
  • 打赏
  • 举报
回复
兄弟愚钝,&m_brRed是如何得到的?
masterz 2001-11-28
  • 打赏
  • 举报
回复
也可以override OnDrawItem() of the parent window:
Override the OnDrawItem() method for your CDialog derived class using Class
Wizard and add the following code, changing variable names as neccessary. It is
important to note that a pointer to a CDC object from the handle of the DC
passed in via the LPDRAWITEMSTRUCT is required, otherwise only the background of
the text will be the desired color.

void CMyDialogDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
// TODO: Add your message handler code here and/or call default

char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush;

CTabCtrl *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB1);

if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
// To determine which tab to be drawn. I assume you only have two tabs
switch (lpdis->itemID)
{
case 0:
cbr = &m_brRed;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
break;

case 1:
cbr = &m_brBlue;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
break;
}

memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;

pTabCtrl->GetItem(lpdis->itemID, &tci);

CDC *dc = CDC::FromHandle(lpdis->hDC);
dc->FillRect(&lpdis->rcItem, cbr);
dc->SetBkColor(bkColor);

TextOut(lpdis->hDC,
lpdis->rcItem.left,
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));
}
// CDialog::OnDrawItem(nIDCtl, lpdis);
}


masterz 2001-11-28
  • 打赏
  • 举报
回复
CTabCtrl::DrawItem
void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CTabCtrl object.
The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before this member function terminates.

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧