xtreme toolkit pro——CXTPReportControl控件教程-3

一、CXTPReportControl的Data Members(Protected:m_)

(Xtreme Toolkit Pro v12.0-> Report Control->Classes-> CXTPReportControl Class->CXTPReportControl Data Members)

class CXTPReportControl : public CWnd;

The CXTPReportControl class provides an implementation of the Report control.

二、CXTPReportControl相关的几个Classes

(Xtreme Toolkit Pro v12.0-> Report Control->Classes-> CXTPReportControl Class)

class CXTPReportColumn;

Represents report column item with its properties and operations.

    CXTPReportColumn* CXTPReportControl::GetFocusedColumn() const; class CXTPReportColumns;

This class is a collection of report columns objects, each of which can be referred to by its zero-based index.

    CXTPReportColumns* CXTPReportControl::GetColumns() const;

    class CXTPReportHeader;

A report header is a part of the report window positioned above columns of text or numbers. It contains a title for each column, and it can be divided into parts. The user can drag the dividers that separate the parts to set the width of each column.

    CXTPReportHeader* CXTPReportControl::GetReportHeader() const;

    class CXTPReportRecord

CXTPReportRecord represents a collection of objects of CXTPReportRecordItem or objects of classes that are children of CXTPReportRecordItem. A collection of such items is one record in ReportControl list. You create an object of CXTPReportRecord by simply calling constructor. After it you can add items to the record. class CXTPReportRecordItem

Class for working with single list cell. Base class for extended list cells. It determines the behavior of all specific record items. You don’t use its class directly in the control. If you wish to add your own Record Item to the control, you must inherit it from CXTPReportRecordItem. Most member functions in this class are virtual.

class CXTPReportRecordItemText : public CXTPReportRecordItem;

This Class represents a text-only cell and inherits basic functionality fromCXTPReportRecordItem class. You create a text record item simply by calling a constructor with one parameter - text string

class CXTPReportRecords

This class represents a records collection class. It supports an array ofCXTPReportRecord pointers.

CXTPReportRecords* CXTPReportControl::GetFooterRecords() const;
CXTPReportRecords* CXTPReportControl::GetHeaderRecords() const; 
CXTPReportRecords* CXTPReportControl::GetRecords() const;

class CXTPReportRow

CXTPReportRow class represents an row of the report control window.

CXTPReportRow* CXTPReportControl::GetFocusedRow() const;

class CXTPReportRows

This class represents a rows collection class. It supports an array ofCXTPReportRow pointers.

CXTPReportRows* CXTPReportControl::GetFooterRows() const;

CXTPReportRows* CXTPReportControl::GetHeaderRows() const;

CXTPReportRows* CXTPReportControl::GetRows() const;

class CXTPReportSelectedRows;

Encapsulates a collection of CXTPReportRow pointers that represent the selected rows in a Report Control.

CXTPReportSelectedRows* pSelRows = pReportControl->GetSelectedRows();

三、在CXTPReportControl增加记录示例

CXTPReportControl m_wndReportCtrl;

(1)、add 3 columns,set column header

for (i = 0; i < 3; i++) 
{   
    CString strName;

    strName.Format(_T("Column %d"), i + 1);

    m_wndReportCtrl.AddColumn(new CXTPReportColumn(i, strName, 280));   
}

(2)、adds 4 empty records to a report control

for(i=0;i<4;i++)

m_wndReportCtrl.AddRecord(new CXTPReportRecord());

(3)、construct the first record and fill the first row

class CXTPReportRecordItemText : public CXTPReportRecordItem;

This Class represents a text-only cell and inherits basic functionality from class. You create a text record item simply by calling a constructor with one parameter - text string

class CXTPReportRecordItemNumber : public CXTPReportRecordItem;

This class represents a numeric cell and inherits basic functionality from class.

class CXTPReportRecordItemDateTime : public CXTPReportRecordItem;

You create a CXTPReportRecordItemDateTime record item simply by calling a constructor with one parameter

//Creates a record text item.

CXTPReportRecordItemText( LPCTSTR szText = _T("") );

//Adds a record item to the internal records item collection.

CXTPReportRecordItem* CXTPReportRecord::AddItem(CXTPReportRecordItem* pItem);

CXTPReportRecord * pRecord = new CXTPReportRecord();

pRecord->AddItem(new CXTPReportRecordItemText(“item1”))

pRecord->AddItem(new CXTPReportRecordItemText(“item2”))

pRecord->AddItem(new CXTPReportRecordItemText(“item3”))

CXTPReportRecord* pRecord = m_wndReportCtrl.AddRecord(pRecord);

四 、CXTPReportControl的事件响应

(消息宏参见Xtreme Toolkit Pro v12.0-> Report Control->Macros)
在CXTPReportControl的消息处理中也有类似ClistView中NM_LISTVIEW结构的XTP_NM_REPORTRECORDITEM结构:

XTP_NM_REPORTRECORDITEM Structure

This structure is sent to Main window in a WM_NOTIFY message from Item and provides all parameters that are needed in processing control specific notifications by the main window

struct XTP_NM_REPORTRECORDITEM {

NMHDR hdr;

CXTPReportRow* pRow;

CXTPReportRecordItem* pItem;

CXTPReportColumn* pColumn;

int nHyperlink;

POINT pt;

};

XTPReportRecordItem.h对比CXTPReportControl::SendMessageToParentXTP_NM_REPORTRECORDITEM结构的参数:

CXTPReportControl::SendMessageToParent Method

Notifies parent control of some event that has happened.

LRESULT SendMessageToParent(

CXTPReportRow *pRow,;

CXTPReportRecordItem *pIt;

UINT nMessage,;

CPoint *pPoint;

int nHyperlink=-1;

)const;

五、CXTPReportControl的事件处理示例

//ListFrame.h消息响应函数声明

afx_msg void OnReportSortOrderChanged(NMHDR* pNMHDR, LRESULT* pResult);

afx_msg void OnReportColumnRClick(NMHDR* pNMHDR, LRESULT* pResult);

afx_msg void OnReportLButtonDown(NMHDR* pNMHDR, LRESULT* pResult);

//ListFrame.cpp消息映射注意包含#include "XTPReportDefines.h"消息宏在此文件中定义

//XTP_NM_REPORT_SORTORDERCHANGED消息

ON_NOTIFY(XTP_NM_REPORT_SORTORDERCHANGED, AFX_IDW_PANE_FIRST, OnReportSortOrderChanged) //XTP_NM_REPORT_HEADER_RCLICK消息

ON_NOTIFY(XTP_NM_REPORT_HEADER_RCLICK, AFX_IDW_PANE_FIRST, OnReportColumnRClick)

//XTP_NM_REPORT_LBUTTONDOWN消息

ON_NOTIFY(XTP_NM_REPORT_LBUTTONDOWN,AFX_IDW_PANE_FIRST, OnReportLButtonDown)

//ListFrame.cpp消息响应处理

//覆写列标题左击排序事件by fan

void CListFrame::OnReportSortOrderChanged(NMHDR* pNMHDR, LRESULT* pResult)

{

    AfxMessageBox(_T("SortOrderChanged"));

}

//添加列标题右击事件XTP_NM_REPORT_HEADER_RCLICK by fan

void CListFrame::OnReportColumnRClick(NMHDR* pNMHDR, LRESULT* pResult)

{

    AfxMessageBox(_T("ColumnRClick"));

}

//添加列表视图左击事件XTP_NM_REPORT_LBUTTONDOWN by fan

void CListFrame::OnReportLButtonDown(NMHDR* pNMHDR, LRESULT* pResult)

{

    XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*)pNMHDR;

    int rowIndex=pItemNotify->pRow->GetIndex();//行号

    int colIndex=pItemNotify->pColumn->GetIndex();//列号

    int colItemIndex=pItemNotify->pColumn->GetItemIndex();//列号

    CString colCaption=pItemNotify->pColumn->GetCaption();//列标题

    int itemIndex=pItemNotify->pItem->GetIndex();//列号

    CString itemCaption=pItemNotify->pItem->GetCaption(pItemNotify->pColumn);//项内容 CString str="";

    str.Format(_T("rowIndex=%d,colIndex=%d,colItemIndex=%d,colCaption=%s,itemIndex=%d,itemCaption=%s"),

    rowIndex,colIndex,colItemIndex,colCaption,itemIndex,itemCaption); AfxMessageBox(str);

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值