码迷,mamicode.com
首页 > Windows程序 > 详细

自绘listCtrl控件选中该行高亮(模拟windows)

时间:2017-06-28 11:02:18      阅读:234      评论:0      收藏:0      [点我收藏+]

标签: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)

标签:flat   点线   creates   cst   int   mst   draw   mha   rom   

原文地址:http://www.cnblogs.com/ye-ming/p/7088454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!