Solved

Select whole line in CListCtrl report view?

Posted on 1998-11-21
3
310 Views
Last Modified: 2013-11-20
Does anyone have a class derived from CListCtrl that will select the entire line in report view rather than just the item?
0
Comment
Question by:duncan2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 400 total points
Comment Utility
Make sure the list ctrl is ownerdrawn and override its DrawItem member function:

void CPublishList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
      CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
      CRect rcItem(lpDrawItemStruct->rcItem);
      UINT uiFlags = ILD_TRANSPARENT;
      int nItem = lpDrawItemStruct->itemID;
      static _TCHAR szBuff[MAX_PATH];
      LPCTSTR pszText;
      COLORREF clrTextSave, clrBkSave;
      CRect rcLabel;
      CRect rcAllLabels;

// get item data

      LV_ITEM lvi;
      lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
      lvi.iItem = nItem;
      lvi.iSubItem = 0;
      lvi.pszText = szBuff;
      lvi.cchTextMax = sizeof(szBuff);
      lvi.stateMask = 0xFFFF;            // get all state flags
      GetItem(&lvi);

      GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
      GetItemRect(nItem, rcItem, LVIR_LABEL);

      BOOL bSelected = lvi.state & LVIS_SELECTED;
      bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);

      if (bSelected)
      {
            clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
            clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

            pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
      }
      else
            pDC->FillRect(rcAllLabels, &CBrush(RGB(255,255,255)));

// draw item label

      pszText = MakeShortString(pDC, szBuff,
                        rcItem.right-rcItem.left, 2*OFFSET_FIRST);

      rcLabel = rcItem;
      rcLabel.left += OFFSET_FIRST;
      rcLabel.right -= OFFSET_FIRST;

      pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);

// draw labels for extra columns

      LV_COLUMN lvc;
      lvc.mask = LVCF_FMT | LVCF_WIDTH;

      for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
      {
            rcItem.left = rcItem.right;
            rcItem.right += lvc.cx;

            int nRetLen = GetItemText(nItem, nColumn,
                                    szBuff, sizeof(szBuff));
            if (nRetLen == 0)
                  continue;

            pszText = MakeShortString(pDC, szBuff,
                  rcItem.right - rcItem.left, 2*OFFSET_OTHER);

            UINT nJustify = DT_LEFT;

            if(pszText == szBuff)
            {
                  switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
                  {
                  case LVCFMT_RIGHT:
                        nJustify = DT_RIGHT;
                        break;
                  case LVCFMT_CENTER:
                        nJustify = DT_CENTER;
                        break;
                  default:
                        break;
                  }
            }

            rcLabel = rcItem;
            rcLabel.left += OFFSET_OTHER;
            rcLabel.right -= OFFSET_OTHER;

            pDC->DrawText(pszText, -1, rcLabel,
                  nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
      }

// draw focus rectangle if item has focus

      if (lvi.state & LVIS_FOCUSED)
            pDC->DrawFocusRect(rcAllLabels);

// set original colors if item was selected

      if (bSelected)
      {
        pDC->SetTextColor(clrTextSave);
            pDC->SetBkColor(clrBkSave);
      }
}

0
 
LVL 5

Expert Comment

by:yonat
Comment Utility
0
 

Expert Comment

by:yif
Comment Utility
test
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now