Self-painted Listctrl control selects the row highlight (simulates windows)

Source: Internet
Author: User
Tags dashed line

Add code in the DrawItem () function of the CListCtrl derived class Cmylistctrl

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 ( in,173,255);  for(inti = 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 is in the frame inside the line, imitating the look of the selected

The Linetype of an entity
Ps_solid Solid Line
Ps_dash Dashed Line
Ps_dot Dot Line
Ps_dashdot Line
Ps_dashdotdot Double-line

Self-painted Listctrl control selects the row highlight (simulates windows)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.