具有报表样式的CListCtrl中的多行文本 [英] Multiline text in CListCtrl with Report Style

查看:190
本文介绍了具有报表样式的CListCtrl中的多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CListCtrl类型的报告.
我需要在其中输入多行文字.

I have CListCtrl type report.
I need to write into it''s items multiline text.

How can i achieve this?

推荐答案

您必须实现自己的CListCtrl
派生形式.
覆盖其对WM_MEASUREITEMWM_DRAWITEM的反应:)
You have to implement an own derivation of CListCtrl

to overwrite its reactions for WM_MEASUREITEM and WM_DRAWITEM :)


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()
};





...
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
  }
}



请记住设置LVS_OWNERDRAWFIXED
在创建控件或在.rc文件中时:)



Please remember to set the LVS_OWNERDRAWFIXED
at creating of your control or in your .rc file :)


默认情况下,CListCtrl不会在多行模式下绘制其文本.
这就是为什么您也需要以下功能的原因:):
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 :)
  }
}


这篇关于具有报表样式的CListCtrl中的多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆