15,979
社区成员
发帖
与我相关
我的任务
分享
void CTZListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 添加您的代码以绘制指定项
HBRUSH hbr;//画背景
if(lpDrawItemStruct->itemState==17)
{
hbr=::CreateSolidBrush(RGB(187,203,255));
::FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,hbr);
}
else
{
hbr=::CreateSolidBrush(RGB(255,255,255));
::FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,hbr);
}
HPEN hpen=::CreatePen(PS_SOLID,1,RGB(236,233,216));//画格子
::SelectObject(lpDrawItemStruct->hDC,hpen);
::MoveToEx(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.bottom,NULL);
::LineTo(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
LOGFONT lf;//以下将要用来显示文字
memset(&lf,0,sizeof(lf));
GetFont()->GetLogFont(&lf);
lf.lfCharSet = CHINESEBIG5_CHARSET;
// memcpy(lf.lfFaceName,"MingLiu",8);
HFONT hfont=::CreateFont(lf.lfHeight,lf.lfWidth,lf.lfEscapement,lf.lfOrientation,lf.lfWeight,lf.lfItalic,lf.lfUnderline,lf.lfStrikeOut,lf.lfCharSet,lf.lfOrientation,lf.lfClipPrecision,lf.lfQuality,lf.lfPitchAndFamily,lf.lfFaceName);
::SelectObject(lpDrawItemStruct->hDC,hfont);
CString itemtext=this->GetItemText(lpDrawItemStruct->itemID,0);//这里取文字,为啥都是空呢?试了GetItem函数也不行。
CString str;
str.Format("%d %s",lpDrawItemStruct->itemID,itemtext);
::TextOut(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left+5,lpDrawItemStruct->rcItem.top,str.GetBuffer(),str.GetLength());
::DeleteObject(hfont);
::DeleteObject(hpen);
::DeleteObject(hbr);
}
void CMyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CString str_text=GetItemText( lpDrawItemStruct->itemID, 0 );
::TextOut( lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top, str_text, str_text.GetLength() );
}