CLISTCTRL often uses ClistCtrl to display a large amount of data, but the background color of the total feel focus line is blue, the effect is very ugly, refer to the example in this book "MFC Technology", modified the clistctrl onpaint code, The focus line changed to a white background, added a rectangular border, the following actual effect, self-feeling is not bad;
Implementation:
1. First call the default, let ClistCtrl painted himself
2, call the getDC () function to get DC
3, call getFont () to get the current font
4, use the getSubiteMRect function to get the rectangle size of each column, then use
DrawText function draws text
5. Finally, use the Rectangle function to draw the border, so that the effect is achieved.
Below is the main code
Void cxlistctrl :: onpaint ()
{
DEFAULT ();
CRECT RECT;
Int nsel = getcursel ();
IF (NSEL <0) return;
CDC * DC = getdc (); // Don't Use CPAINTDC
Cfont * pfont = getFont ();
// Brush the background brush as white
GetItemRect (NSEL, RECT, LVIR_BOUNDS);
CBRUSH Brush (RGB (255, 255, 255);
CBRUSH * POLDBRUSH = DC-> SelectObject (& brush);
DC-> Rectangle (Rect.Lep, Rect.top, Rect.right, Rect.bottom);
// Start the text of each column of the focus line
CFont * PoldFont = DC-> SelectObject (PFont);
CString Strtemp;
INT nColumns = getColumns ();
HDITEM HDITEM;
Uint nformat;
INT NFMT;
For (int i = 0; i { Strtemp = GetItemText (NSEL, I); GetSubitemRect (NSEL, I, LVIR_BOUNDS, REC); / / Get aligned in each column HDITEM.MASK = HDI_FORMAT; M_HeaderCtrl.getItem (i, & hditem); NFMT = HDITEM.FMT & HDF_JUSTIFYMASK; Nformat = dt_vcenter | dt_singeline; IF (nfmt == hdf_center) NFORMAT | = DT_Center; Else IF (nfmt == HDF_LEFT) Nformat | = dt_left; Else NFORMAT | = DT_RIGHT; DC-> DrawText (strTemp, & Rect, nformat); } // Sea Box CPEN * POLDPEN = DC-> SelectObject (m_selpen); GetItemRect (NSEL, RECT, LVIR_BOUNDS); DC-> SelectStockObject (null_brush); // Set null_brush DC-> Rectangle (Rect.Lep, Rect.top, Rect.right, Rect.bottom); DC-> SELECTOBJECT (POLDPEN); DC-> SELECTOBJECT (POLDBRUSH); DC-> SelectObject (PFont); In the process of implementation, you should pay attention to the problem: 1, the font of the focus is the same as the font of other rows. 2, alignment of each column 3, after painting the text of the focus, then draw the outside frame Of course, this is just a kind of effect, and you can draw another effect you need;