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):
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:
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));
to this:
CPen Pen(PS_SOLID, 1, GetSysColor(COLOR_WINDOW)^RGB(0x33,0x33,0));
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);
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) {
if((lvi.state & LVIS_DROPHILITED) || HasFocus) {
pDC->SetBkColor (GetSysColor(COLOR_HIGHLIGHT ));
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
}else{
pDC->SetBkColor (GetSysColor(COLOR_BTNFACE));
pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
}
}else{
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;
for(int Col=0; GetColumn(Col, &lvc); ++Col) {
CellRect.left=CellRect.right;
CellRect.right+=lvc.cx;
pDC->FillSolidRect(CellRect, pDC->GetBkColor());
if((CellRect.rightVisibleRect.right)) continue;
lvi.iSubItem=Col;
GetItem(&lvi);
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;
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;
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);
}
if((lvi.state & LVIS_FOCUSED) && HasFocus) pDC->DrawFocusRect(Rect);
}
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.