www.pudn.com > HReportTest.rar > HReportListBase.h


// HReportListBase.h: interface for the CHReportListBase class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_HREPORTLISTBASE_H__AB1B1BE3_9E1E_41B4_A9D7_E991241E2F09__INCLUDED_) 
#define AFX_HREPORTLISTBASE_H__AB1B1BE3_9E1E_41B4_A9D7_E991241E2F09__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include "HFlatHeaderCtrl.h" 
#include "HListSort.h" 
 
class CHReportListBase   
{ 
public: 
	CHReportListBase(); 
	virtual ~CHReportListBase(); 
 
	// 更新所有的行 
	virtual void UpdateAllRows() { } 
 
	// 更新指定行 
	virtual void UpdateRow(int nRow) { } 
 
	int HitTestEx(CPoint point, int& nCol); 
 
	// 设定当前选中行( 仅限 LVS_SINGLESEL ) 
	// nRow = -1 表示不选中 
	void SetCurSel(int nRow); 
 
	// 得到当前所选行( 仅限 LVS_SINGLESEL ) 
	// 返回-1 表示当前没有选中任何一行 
	int GetCurSel(); 
 
	// 计算删除当前所选行后将要被选中的行 
	// 返回 -1 表示删除后没有选中行 
	int CalcNextSel(int nRow); 
 
	void SetUsedStyle(	BOOL bFullRowSelect = TRUE,  
						BOOL bShowGridLines = TRUE,  
						BOOL bSingleSel = TRUE); 
	 
	// Subclass CHFlatHeaderCtrl 
	BOOL SubclassHeader(); 
 
	DWORD GetExtendedStyle()  
	{ 
		ASSERT(::IsWindow(m_pListCtrl->GetSafeHwnd()));  
		return (DWORD)m_pListCtrl->SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); 
	} 
 
	void SetExtendedStyle(DWORD dwExStyle)  
	{ 
		ASSERT(::IsWindow(m_pListCtrl->GetSafeHwnd()));  
		m_pListCtrl->SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, GetExtendedStyle()|dwExStyle); 
	} 
 
	CHeaderCtrl* GetHeaderCtrlX() const  
	{ 
		CHeaderCtrl * const pHeaderCtrl =  
			(CHeaderCtrl*) m_pListCtrl->GetDlgItem(0); 
		 
		ASSERT(pHeaderCtrl != NULL); 
		return pHeaderCtrl; 
	} 
 
protected: 
	// 当绘制某行时 
	// 返回TRUE则要自定义绘制子列, 否则用默认方法绘制子列 
	virtual BOOL OnCustomDrawItem(int nItem, COLORREF& clrText, COLORREF& clrTextBk) { return FALSE; } 
 
	// 当绘制某行的子列时 
	virtual void OnCustomDrawSubItem(int nItem, int nSubItem, COLORREF& clrText, COLORREF& clrTextBk) { } 
 
	// 当鼠标左键单击时 
	virtual void OnClickImpl(CPoint pt, int nItem) { } 
 
	// 当鼠标左键双击时 
	virtual void OnDbClickImpl(CPoint pt, int nItem) { } 
 
	// 当鼠标右键单击时 
	virtual void OnRclickImpl(CPoint pt, int nItem) { } 
 
	// 根据nCol列进行排序 
	virtual BOOL SortList(int nCol, BOOL bAscending)  
	{ 
		CHListSort csc(m_pListCtrl, nCol); 
		csc.Sort (bAscending, DT_STRING); 
		return TRUE; 
	} 
 
	// 固定设为 LVS_REPORT 类型 
	void PreCreateWindowImpl_Pre(CREATESTRUCT& cs) { cs.style |= LVS_REPORT; } 
 
	class CListCtrl_Friendly : public CListCtrl 
	{ 
		friend class CHReportListBase; 
	}; 
 
	void AttachImpl(CListCtrl *pListCtrl) 
	{ 
		m_pListCtrl = (CListCtrl_Friendly *)pListCtrl; 
	} 
 
	// 把列宽度保存到注册表 
	void SaveColumnWidths(); 
 
	// 根据注册表读出的列信息设置各列宽度 
	void LoadColumnWidths(); 
 
	virtual BOOL OnNotifyImpl(WPARAM wParam, LPARAM lParam, LRESULT* pResult); 
	virtual void PreSubclassWindowImpl_Post(); 
	afx_msg int OnCreateImpl_Post(LPCREATESTRUCT lpCreateStruct); 
	afx_msg void OnCustomDrawImpl(NMHDR* pNMHDR, LRESULT* pResult); 
	afx_msg void OnDestroyImpl_Pre(); 
	afx_msg BOOL OnEraseBkgndImpl(CDC* pDC); 
	afx_msg void OnPaintImpl(); 
 
private: 
	BOOL FontExists(CString &strFaceName); 
	BOOL CreateSysFont( LOGFONT& lf,  
						CFont& font,  
						long lfWeight = FW_NORMAL,  
						char lfUnderline = 0,  
						long lfOrientation = 0,  
						long lfEscapement = 0); 
 
protected: 
	void InitFont(); 
	CListCtrl_Friendly*		m_pListCtrl; 
    
	CHFlatHeaderCtrl	m_flatHeader; 
	CImageList			m_imageList; 
	CFont				m_font; 
 
	int		m_nLineHeight;	// 行高, 在继承类的构造函数中更改行高 
	int		m_nSortedCol;   // index of currently selected column 
 
	BOOL	m_bAscending; 
	BOOL	m_bAutoSave;	// true if saving column widths. 
	BOOL	m_bAutoFont;	 
	 
	CString		m_strSection;   // registry section name. 
	CString		m_strEntry;	 // registry entry name. 
	CString		m_strDefault;   // registry default value. 
	 
	COLORREF	m_clrText;	  // RGB value for row text color. 
	COLORREF	m_clrTextBk;	// RGB value for row text background color. 
}; 
 
#endif // !defined(AFX_HREPORTLISTBASE_H__AB1B1BE3_9E1E_41B4_A9D7_E991241E2F09__INCLUDED_)