CListCtrl
Full Row Select
Site Map Feedback
Up Properties Select Sort
The CListCtrl has an overridable void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); function...
But you need to know what the original code is to make your changes!
Most people don't have access to the source of CommCtrl.dll, and code found on the internet was buggy and over-complicated, so this code was developed.
This is intended for a CListCtrl or CListView with [Properties][Styles Tab][View][Report] and [Properties][More Styles Tab][Owner draw fixed] both checked.
You have to have a Subclassed CListCtrl class, then just paste the RowSelect.h code into it and make any other adjustments you need.
As an example of the changes you could make, blue lines between rows can be added and the selection highlight colour can be made to look like a highlighter pen (when viewed with the standard Windows Appearance):
A selected row in CListCtrl
This requires the following alterations to the code:
Change this:
    pDC->SetBkColor  (GetSysColor(Highlight ? COLOR_HIGHLIGHT     : COLOR_WINDOW    ));
    pDC->SetTextColor(GetSysColor(Highlight ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
To this:
//                          This: 0xFFFFFF^ makes a highlighter yellow selection in standard windows Appearance. It works for everything except the "High Contrast White" Schemes.
    pDC->SetBkColor  (Highlight ? 0xFFFFFF^GetSysColor(COLOR_HIGHLIGHT    ) : GetSysColor(COLOR_WINDOW    ));
    pDC->SetTextColor(Highlight ? 0xFFFFFF^GetSysColor(COLOR_HIGHLIGHTTEXT) : GetSysColor(COLOR_WINDOWTEXT));
for the highlighting, and change this:
    CPen Pen(PS_SOLID, 1, GetSysColor(COLOR_INACTIVECAPTION)); // Row separating Lines (Windows Explorer appears to use this colour for the lines in the Tree View, so that is used here too.
to this:
    CPen Pen(PS_SOLID, 1, GetSysColor(COLOR_WINDOW)^RGB(0x33,0x33,0)); // Row separating Lines
for blue grid lines (makes the page look like standard (UK) lined paper).
  void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {
    CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect Rect(lpDrawItemStruct->rcItem);
    int Row=lpDrawItemStruct->itemID;
    CImageList* pImageList=GetImageList(LVSIL_SMALL);
    bool HasFocus=(GetFocus()==this);
    // Get item image and state info
    LV_ITEM lvi;
    lvi.mask=LVIF_IMAGE | LVIF_STATE;
    lvi.iItem=Row;
    lvi.iSubItem=0;
    lvi.stateMask=-1;
    GetItem(&lvi);
    CRect VisibleRect;
    GetClientRect(&VisibleRect);
    VisibleRect.top=Rect.top;
    VisibleRect.bottom=Rect.bottom;

    if(lvi.state & LVIS_SELECTED) { // Selected:
      if((lvi.state & LVIS_DROPHILITED) || HasFocus) { // Hilight:
        pDC->SetBkColor  (GetSysColor(COLOR_HIGHLIGHT    ));
        pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
      }else{ // Not got the Focus, but has ShowselAlways set:
        pDC->SetBkColor  (GetSysColor(COLOR_BTNFACE));
        pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
      }
    }else{ // Not Selected:
      pDC->SetBkColor  (GetSysColor(COLOR_WINDOW    ));
      pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
    }

    LVCOLUMN lvc;
    lvc.mask=LVCF_FMT | LVCF_WIDTH;
    CRect CellRect(Rect);
    CellRect.right=CellRect.left; // Add the column width to it in the Column loop:
    for(int Col=0; GetColumn(Col, &lvc); ++Col) {
      CellRect.left=CellRect.right; // Next cell
      CellRect.right+=lvc.cx; // Keep track of the right of the cell
      // Erase the background (the last column may have overdrawn an icon to this column). this is probably faster and definitely easier than clipping an icon draw.
      pDC->FillSolidRect(CellRect, pDC->GetBkColor());

      if((CellRect.rightVisibleRect.right)) continue; // Clipping: loop until a visible cell is found.

      lvi.iSubItem=Col;
      GetItem(&lvi);

      // Draw the Row's State Icon:
      if((Col==0) && (CellRect.right>VisibleRect.left) && (lvi.state & LVIS_STATEIMAGEMASK) && GetImageList(LVSIL_STATE)) GetImageList(LVSIL_STATE)->Draw(pDC, ((lvi.state & LVIS_STATEIMAGEMASK)>>12)-1, CellRect.TopLeft(), ILD_TRANSPARENT);

      if(pImageList && lvi.iImage!=-1) {
        CellRect.left+=pDC->GetTextExtent(" ",1).cx<<1; // Text and Icons are spaced by an amount related to the width of a Space character
        pImageList->Draw(pDC, lvi.iImage, CellRect.TopLeft(), ILD_TRANSPARENT);
        CellRect.left+=16;
      }
      CString sText=GetItemText(Row, Col);
      if(sText.GetLength()==0) continue;

      UINT nJustify=DT_LEFT; // Get the text justification
      switch(lvc.fmt & LVCFMT_JUSTIFYMASK) {
        case LVCFMT_CENTER: nJustify=DT_CENTER; break;
        case LVCFMT_RIGHT : nJustify=DT_RIGHT ; break;
      }
      pDC->DrawText(' '+sText+' ', -1, CellRect, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS);
    }
/* Customisation example: uncomment this block to have row-separating lines:
    CPen Pen(PS_SOLID, 1, GetSysColor(COLOR_INACTIVECAPTION)); // Row separating Lines (Windows Explorer appears to use this colour for the lines in the Tree View, so that is used.
    CPen* OldPen=pDC->SelectObject(&Pen);
    pDC->MoveTo(VisibleRect.left , VisibleRect.bottom-1);
    pDC->LineTo(VisibleRect.right, VisibleRect.bottom-1);
    pDC->SelectObject(OldPen);
*/
    if((lvi.state & LVIS_FOCUSED) && HasFocus) pDC->DrawFocusRect(Rect); // Draw focus rectangle if item has focus
  }

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.