正文

Xtreme Toolkit中的CXTPReportControl类2009-04-06 22:02:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/xman/42008.html

分享到:

一.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 from CXTPReportRecordItem 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 of CXTPReportRecord 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 of CXTPReportRow 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 CXTPReportRecordItem 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 CXTPReportRecordItem class. class CXTPReportRecordItemDateTime : public CXTPReportRecordItem; You create a CXTPReportRecordItemDateTime record item simply by calling a constructor with one COleDateTime 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::SendMessageToParent与XTP_NM_REPORTRECORDITEM结构的参数: CXTPReportControl::SendMessageToParent Method Notifies parent control of some event that has happened. LRESULT SendMessageToParent(                                  CXTPReportRow* pRow,                                  CXTPReportRecordItem* pItem,                                  CXTPReportColumn* pColumn,                                  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); }

阅读(9692) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册