64,648
社区成员
发帖
与我相关
我的任务
分享
void GEPTLits::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
LVITEM lvi = {0};
lvi.mask = LVIF_STATE;//|LVIF_IMAGE;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED ;
lvi.iItem = lpDIS->itemID;
BOOL bGet = GetItem(&lvi);
BOOL bHighlight =((lvi.state & LVIS_DROPHILITED)||((lvi.state & LVIS_SELECTED) &&
((GetFocus() == this)|| (GetStyle() & LVS_SHOWSELALWAYS))));
// 画文本背景
//这里是改变了所有的图片的颜色,如果想更改特定的的表格,那么请在else if里 判断lvi.iSubItem.
CRect rcBack = lpDIS->rcItem;
pDC->SetBkMode(TRANSPARENT);
if( bHighlight )
{
pDC->SetTextColor(RGB(0,128,255));
pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC->FillRect(rcBack, &CBrush(RGB(219, 251, 118)));
}
else
{
pDC->SetTextColor(RGB(0,128,255));
//pDC->FillRect(rcBack, &CBrush(0xE3e3e3));
pDC->FillRect(rcBack, &CBrush(RGB(255, 255, 255)));
}
if (lpDIS->itemAction & ODA_DRAWENTIRE)
{
//写文本
CString szText;
for (int i = 0; i < 11; i++)
{ //循环得到文本
CRect rcItem;
if ( !GetSubItemRect(lpDIS->itemID, i, LVIR_LABEL, rcItem ))
continue;
szText = GetItemText( lpDIS->itemID, i );
rcItem.left += 5; rcItem.right -= 1;
pDC->DrawText(szText, lstrlen(szText), &rcItem, DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE);
}
}
}
void GEPTLits::OnPaint()
{
// First let the control do its default drawing.
const MSG *msg = GetCurrentMessage();
DefWindowProc( msg->message, msg->wParam, msg->lParam );
// Draw the lines only for LVS_REPORT mode
if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT )
{
// Get the number of columns
CClientDC dc(this );
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();
CPen pen;
pen.CreatePen(0,2,RGB(255,0,0));
CPen* pOldPen=(CPen*)dc.SelectObject(&pen);
// The bottom of the header corresponds to the top of the line
RECT rect;
pHeader->GetClientRect( &rect );
int top = rect.bottom;
// Now get the client rect so we know the line length and
// when to stop
GetClientRect( &rect );
// The border of the column is offset by the horz scroll
int borderx = 0 - GetScrollPos( SB_HORZ );
CBrush brush1; // Must initialize!
dc.SetBkColor(RGB(255,0,0));
for( int i = 0; i < nColumnCount; i++ )
{
// Get the next border
borderx += GetColumnWidth( i );
// if next border is outside client area, break out
if( borderx >= rect.right ) break;
// Draw the line.
dc.MoveTo( borderx-1, top);
dc.LineTo( borderx-1, rect.bottom );
}
// Draw the horizontal grid lines
// First get the height
if( !GetItemRect( 0, &rect, LVIR_BOUNDS ))
return;
int height = rect.bottom - rect.top;
GetClientRect( &rect );
int width = rect.right;
for(i = 1; i <= GetCountPerPage(); i++ )
{
dc.MoveTo( 0, top + height*i);
dc.LineTo( width, top + height*i );
}
// dc.SelectObject(pTempBrush);
}
}