標籤:flat 點線 creates cst int mst draw mha rom
CListCtrl的衍生類別CMyListCtrl的DrawItem()函數裡添加代碼
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); if (lpDrawItemStruct->itemState && LVIS_SELECTED) { CPen PenLine(PS_SOLID, 1, RGB(0, 0, 0)); CPen *OldPenLine = pDC->SelectObject(&PenLine); rcItem.right -= 2; rcItem.bottom -= 2; pDC->MoveTo(rcItem.left, rcItem.top); pDC->LineTo(rcItem.right, rcItem.top); pDC->MoveTo(rcItem.left, rcItem.top); pDC->LineTo(rcItem.left, rcItem.bottom); pDC->MoveTo(rcItem.left, rcItem.bottom); pDC->LineTo(rcItem.right, rcItem.bottom); pDC->MoveTo(rcItem.right, rcItem.top); pDC->LineTo(rcItem.right, rcItem.bottom); pDC->SelectObject(OldPenLine); rcItem.DeflateRect(2, 2, 2, 2); COLORREF m_color = RGB(71, 173, 255); for (int i = rcItem.Height() / 2; i>0; i--) { CPen pen(PS_SOLID, 1, m_color); CPen *OldPen = pDC->SelectObject(&pen); pDC->MoveTo(rcItem.left, rcItem.top + i); pDC->LineTo(rcItem.right, rcItem.top + i); pDC->MoveTo(rcItem.left, rcItem.bottom - i); pDC->LineTo(rcItem.right, rcItem.bottom - i); pDC->SelectObject(OldPen); } pDC->SetTextColor(RGB(255, 255, 255)); } else { pDC->SetTextColor(RGB(0, 0, 0)); CBrush brush; brush.CreateSolidBrush(RGB(255, 255, 255)); pDC->FillRect(rcItem, &brush); } CString strText = GetItemText(nRow, 0); CRect rcSubItem; GetSubItemRect(nRow, 0, LVIR_LABEL, rcSubItem); pDC->DrawText(strText, rcSubItem, DT_CENTER);
PenLine是在框內畫線,模仿被選中的樣子
圖元的線型
PS_SOLID 實線
PS_DASH 虛線
PS_DOT 點線
PS_DASHDOT 點化線
PS_DASHDOTDOT 雙點化線
自繪listCtrl控制項選中該行高亮(類比windows)