CGridCtrl学习指南(4)

2020-08-23 20:21

{

CGridCellBase* pCell1 = (CGridCellBase*) lParam1;

CGridCellBase* pCell2 = (CGridCellBase*) lParam2;

if (!pCell1 || !pCell2) return 0;

int nValue1 = _ttol(pCell1->GetText());

int nValue2 = _ttol(pCell2->GetText());

if (nValue1 < nValue2)

return -1;

else if (nValue1 == nValue2)

return 0; else

return 1; }

还提供了两个有用的函数:

int CALLBACK CGridCtrl::pfnCellTextCompare(LPARAM lParam1,

LPARAM lParam2,

LPARAM lParamSort)

int CALLBACK CGridCtrl::pfnCellNumericCompare(LPARAM lParam1,

LPARAM lParam2,

LPARAM lParamSort)

这两个函数是通过文本内容和数值进行排序的(分别使用itoa)。为Grid设置比较函数,仅仅需要调用:

m_Grid.SetCompareFunction(CGridCtrl::pfnCellNumericCompare);

如果这个比较函数设置为空,那么将默认调用函数CGridCtrl::pfnCellTextCompare

打印

void EnableWysiwygPrinting(BOOL bEnable = TRUE) 设置WYSIWYG 打印

BOOL GetWysiwygPrinting() 如果设置了WYSIWYG打印则返回TRUE。

void Print() 在用户选择的设备上打印G rid (控件在对话框中有用)

virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo) 用于文档/浏览环境下,在 CView dervied class' OnBeginPrinting中调用

virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo) 用于文档/浏览环境下. 在CView dervied class' OnPrint中调用

virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo) 用于文档/浏览环境下. 在CView dervied class' OnEndPrinting中调用。

void SetShadedPrintOut(BOOL bEnable = TRUE) 如果为TRUE,则近似打印彩色单元格。如果为FALSE ,则所有文本按照白纸黑字的形式打印出来。.

BOOL GetShadedPrintOut() 判断单元格是否阴影或近似打印。.

void SetPrintMarginInfo(int nHeaderHeight, int nFooterHeight, int nLeftMargin, int nRightMargin, int nTopMargin, int nBottomMargin, int nGap) 设置打印边缘信息。.

void GetPrintMarginInfo(int &nHeaderHeight, int &nFooterHeight, int &nLeftMargin, int &nRightMargin, int &nTopMargin, int &nBottomMargin, int &nGap) 获取打印边缘信息.

结构、定义和消息

CGridCellBase类

这个类是所有Grid单元格类的基类,包含有每个单元格的信息。同时,它还定义了大量的方法供Grid调用,例如画图和打印。几乎所有的方法和函数都是虚拟模式,类本身不能直接使用--只能被引用。作为Grid控件的默认单元格类CGridCell就是基于CGridCellBase的。 属性

virtual void SetText(LPCTSTR szText);

virtual void SetImage(int nImage);

virtual void SetData(LPARAM lParam);

virtual void SetState(DWORD nState);

virtual void SetFormat(DWORD nFormat);

virtual void SetTextClr(COLORREF clr);

virtual void SetBackClr(COLORREF clr);

virtual void SetFont(const LOGFONT* plf);

virtual void SetGrid(CGridCtrl* pGrid);

virtual void SetCoords(int nRow, int nColumn);

virtual void SetMargin(UINT nMargin);

virtual LPCTSTR GetText() const // 返回单元格的文本内容

virtual LPCTSTR GetTipText() const // 根据意愿返回标题提示文本

virtual int GetImage() const // 返回单元格的图形索引

virtual LPARAM GetData() const // 返回单元格的关联数据

virtual DWORD GetState() const // 返回单元格的状态

virtual DWORD GetFormat() const // 返回单元格的格式

virtual COLORREF GetTextClr() const // 返回单元格文本颜色

virtual COLORREF GetBackClr() const // 返回单元格背景颜色

virtual LOGFONT* GetFont() const // 以LOGFONT的形式返回单元格的字体

virtual CFont* GetFontObject() const // 将单元格的字体返回成Cfont对象

virtual UINT GetMargin() const // returns internal margin for cell

virtual CGridCtrl* GetGrid() const // 返回与单元格关联的Grid

virtual CWnd* GetEditWnd() const // 返回NULL或单元格的编辑窗口

virtual BOOL IsEditing() const

virtual BOOL IsFocused() const

virtual BOOL IsFixed() const

virtual BOOL IsFixedCol() const

virtual BOOL IsFixedRow() const

virtual BOOL IsSelected() const

virtual BOOL IsReadOnly() const

virtual BOOL IsModified() const

virtual BOOL IsDropHighlighted() const

virtual BOOL IsDefaultFont() const // 如果单元格使用的是默认字体,返回TRUE

virtual CGridCellBase* GetDefaultCell() const;

操作符

virtual void operator=(CGridCellBase& cell);

操作

virtual void Reset();

virtual BOOL Draw(CDC* pDC, int nRow, int nCol, CRect rect,

BOOL bEraseBkgnd = TRUE);

virtual BOOL GetTextRect( LPRECT pRect) - 单元格内部文本框

virtual BOOL GetTipTextRect( LPRECT pRect) - 工具提示的边框

virtual CSize GetTextExtent(LPCTSTR str) -文本大小

virtual CSize GetCellExtent(CDC* pDC) - 单元格大小

// 开启和终止对单元格的编辑

virtual BOOL Edit(int nRow, int nCol, CRect rect,

CPoint point, UINT nID, UINT nChar)

virtual void EndEdit()

// 确认编辑的结果.如果\不是一个有效的值,那么返回FALSE并且编辑无效

virtual BOOL ValidateEdit(LPCTSTR str);

virtual BOOL PrintCell(CDC* pDC, int nRow, int nCol, CRect rect);

//仅仅只能被基类CgridCellBase调用而不是CgridCellBase本身.

LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);

重载

virtual void OnEndEdit();

virtual void OnMouseEnter();

virtual void OnMouseOver();

virtual void OnMouseLeave();

virtual void OnClick( CPoint PointCellRelative);

virtual void OnClickDown( CPoint PointCellRelative);

virtual void OnRClick( CPoint PointCellRelative);

virtual void OnDblClick( CPoint PointCellRelative);

virtual BOOL OnSetCursor();

重载使得制作普通单元格变的极为简单。为创建自己的单元格类,既可以重载CGridCtrl::CreateCell也可以创建自己的源于CGridCellBase的单元格,或者使用CGridCtrl::SetCellType 和 CGridCtrl::SetDeafaultCellType自动产生。

仅仅需要创建一个源于CGridCellBase 或CGridCell (如CMyGridCell)的新单元格类,然后在Grid中调用如下函数代替原来的单元格就可以了。

MyGrid.SetCellType(row, column, RUNTIME_CLASS(CMyGridCell));

现在的单元格(行、列)就是CMyGridCell类型的

CGridCell类

这个类起源于CGridCellBase并且提供一个使用CGridCtrl的默认实现。

CcellID类

这是一个用来参考个别单元格的便利的辅助类。所有的成员都是公共的。这个类是根据Joe Willcoxsons的最初实现改写的。

class CCellID {

public:

int row, col; // 基于0的单元格的行和列.

CCellID(int nRow = -1, int nCol = -1)

int IsValid();

int operator==(const CCellID& rhs);

int operator!=(const CCellID& rhs);

}

CCellRange类

这是一个用来参考单元格范围的便利的辅助类。这是一个从Joe Willcoxsons最初实现改写的类。

class CCellRange {

public:

CCellRange(int nMinRow = -1, int nMinCol = -1,

int nMaxRow = -1, int nMaxCol = -1);

void Set(int nMinRow = -1, int nMinCol = -1,

int nMaxRow = -1, int nMaxCol = -1);

int IsValid() const;


CGridCtrl学习指南(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:数据库原理重点总结

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: