Click here to Skip to main content
15,879,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have CListCtrl type report.
I need to write into it's items multiline text.

How can i achieve this?
Posted

You have to implement an own derivation of CListCtrl

to overwrite its reactions for WM_MEASUREITEM and WM_DRAWITEM :)
 
Share this answer
 
class CYourCtrl : public CListCtrl
{
public:
  CYourCtrl();
  virtual ~CYourCtrl();
protected: 
  //{{AFX_MSG(CYourCtrl) 
  virtual void DrawItem       (LPDRAWITEMSTRUCT);
  afx_msg void MeasureItem    (LPMEASUREITEMSTRUCT);    
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};


C++
...
BEGIN_MESSAGE_MAP(CYourCtrl, CListCtrl)
    ON_WM_MEASUREITEM_REFLECT()    
END_MESSAGE_MAP()

//
void CYourCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
  if (lpMeasureItemStruct) {
    lpMeasureItemStruct->itemHeight = ...; // set your hight here
  }
}


Please remember to set the LVS_OWNERDRAWFIXED
at creating of your control or in your .rc file :)
 
Share this answer
 
By default CListCtrl does not draw its textes in the multiline mode.
That is why you need the following function too :) :
void CYourCtrl::DrawItem(LPDRAWITEMSTRUCT pDIS)
{
  if (pDIS) {
    // the first step
    if (ODA_DRAWENTIRE == pDIS->itemAction) {
      // Draw your content here
    }
    // there are other cases too :)
  }
}
 
Share this answer
 
Do you have a variable of the control
in the CYourView : public CFormView ?

Please place it there (if not) of the type CYourCtrl
and create it:

void CYourView::OnInitialUpdate()
{
  m_cYourCtrl.Create(..);
  // Set styles here
...
}

void CYourView::OnDestroy()
{
  m_cYourCtrl.DestroyWindow();
...
}

Now you could use some words about the working :)
 
Share this answer
 
It would be OK by replacing of CListCtrl with CYourCtrl, yes :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900