自繪listCtrl控制項選中該行高亮(類比windows)

來源:互聯網
上載者:User

標籤: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)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.