怎么改变CListCtrl中Item的字体

yongdu 2000-07-13 04:09:00
...全文
147 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
FBStudio 2000-07-18
  • 打赏
  • 举报
回复
ad的方法最好。
其实SetFont是CWnd的成员函数,从CWnd派生出来的类自然继承了该函数。
bird2000 2000-07-18
  • 打赏
  • 举报
回复
ad is right.

最好用CListCtrl->sendmessage(WM_SETFONT ,(WPARAM) hfont,MAKELPARAM(fRedraw, 0) );

ad 2000-07-13
  • 打赏
  • 举报
回复
CListCtrl不是有一个函数叫SetFont()吗!
zzh 2000-07-13
  • 打赏
  • 举报
回复
最简单的办法是设置Dialog对话框中字体的大小,如果要对ListCtrl中每一行使用不同的字体,这要从CListCtrl中继承一个类,自己写代码了。
VC6 CListCtrl继承类例子 oid CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: 添加您的代码以绘制指定项 TCHAR lpBuffer[256]; LV_ITEM lvi; lvi.mask = LVIF_TEXT | LVIF_PARAM ; lvi.iItem = lpDrawItemStruct->itemID ; lvi.iSubItem = 0; lvi.pszText = lpBuffer ; lvi.cchTextMax = sizeof(lpBuffer); VERIFY(GetItem(&lvi)); LV_COLUMN lvc, lvcprev ; ::ZeroMemory(&lvc, sizeof(lvc)); ::ZeroMemory(&lvcprev, sizeof(lvcprev)); lvc.mask = LVCF_WIDTH | LVCF_FMT; lvcprev.mask = LVCF_WIDTH | LVCF_FMT; CDC* pDC; pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rtClient; GetClientRect(&rtClient); for ( int nCol=0; GetColumn(nCol, &lvc); nCol++) { if ( nCol > 0 ) { // Get Previous Column Width in order to move the next display item GetColumn(nCol-1, &lvcprev) ; lpDrawItemStruct->rcItem.left += lvcprev.cx ; lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left; } CRect rcItem; if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem)) continue; ::ZeroMemory(&lvi, sizeof(lvi)); lvi.iItem = lpDrawItemStruct->itemID; lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.iSubItem = nCol; lvi.pszText = lpBuffer; lvi.cchTextMax = sizeof(lpBuffer); VERIFY(GetItem(&lvi)); CRect rcTemp; rcTemp = rcItem; if (nCol==0) { rcTemp.left -=2; } if ( lpDrawItemStruct->itemState & ODS_SELECTED ) { pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ; pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ; } else { COLORREF color; color = GetBkColor(); pDC->FillSolidRect(rcTemp,color); if (FindColColor(nCol,color)) { pDC->FillSolidRect(rcTemp,color); } if (FindItemColor(nCol,lpDrawItemStruct->itemID,color)) { pDC->FillSolidRect(rcTemp,color); } //pDC->SetTextColor(m_color); } pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); UINT uFormat = DT_CENTER ; if (m_Header.m_Format[nCol]=='0') { uFormat = DT_LEFT; } else if (m_Header.m_Format[nCol]=='1') { uFormat = DT_CENTER; } else if (m_Header.m_Format[nCol]=='2') { uFormat = DT_RIGHT; } TEXTMETRIC metric; pDC->GetTextMetrics(&metric); int ofst; ofst = rcItem.Height() - metric.tmHeight; rcItem.OffsetRect(0,ofst/2); pDC->SetTextColor(m_color); COLORREF color; if (FindColTextColor(nCol,color)) { pDC->SetTextColor(color); } if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color)) { pDC->SetTextColor(color); } CFont nFont ,* nOldFont; nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体 nOldFont = pDC->SelectObject(&nFont); DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), &rcItem, uFormat) ; pDC->SelectStockObject(SYSTEM_FONT) ; } }

16,471

社区成员

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

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

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