码迷,mamicode.com
首页 > 编程语言 > 详细

MFC Grid control 2.27

时间:2016-08-04 17:41:03      阅读:933      评论:0      收藏:0      [点我收藏+]

标签:

原文链接地址:http://www.codeproject.com/Articles/8/MFC-Grid-control

MFCGridCtrl是个强大的类,用于数据的表格显示。

1.类特征

    • Cell selection using the mouse, with optional Control and Shift key combinations. Selection can be disabled.
    • Row and Column resizing. Sizing can be disabled for row, columns or both.
    • Auto row or column sizing when dividers are double-clicked.
    • Any number of fixed rows and columns.
    • Individual cells can have separate text and background colours.
    • Individual cells can have separate fonts.
    • Individual cells can be marked "Read-Only", or have their modification status set and checked.
    • OLE Drag and drop.
    • Ctrl-C, Ctrl-X and Ctrl-V perform clipboard copy, cut and paste, and Ctrl-A for "Select All"
    • In place editing of cell contents. If a character key is pressed while a cell has focus, editing will start on that cell, and the arrow keys will allow navigation to other keys. If the current focus cell is clicked on, editing will start and the arrow keys will move the carat inside the edit control. Editing can be disabled.
    • Support for Microsoft intellimouse.
    • Optional grid lines.
    • Images in any cell
    • "Virtual" mode for large datasets
    • Full printing support, for either a Doc/View environment (inc Print preview) or a standalone dialog based app (no print preview).
    • Optional "List mode", including full row selection, single row selection, and sort on column header click.
    • Numerous virtual functions to allow this control to be extended very easily.
    • Unicode support.
    • WinCE support
    • Titletips for cells that are too small to display their data.
    • Hidden rows and columns
    • Compiles under VC 4.2, 5.0, 6.0 and under the CE toolkit version 2.0 and 3.0

2.构造

CGridCtrl grid;
grid.Create(rect, pParentWnd, nID);

3.行列数相关函数

int GetRowCount() const            //Returns the number of rows (including fixed rows)
int GetColumnCount() const        //Returns the number of columns (including fixed columns)
int GetFixedRowCount() const    //Returns the number of fixed rows
int GetFixedColumnCount() const    //Returns the number of fixed columns
BOOL SetRowCount(int nRows)        //Sets the number of rows (including fixed rows), Returning TRUE on success.
BOOL SetColumnCount(int nCols)    //Sets the number of columns (including fixed columns), Returning TRUE on success.
BOOL SetFixedRowCount(int nFixedRows = 1)     //Sets the number of fixed rows, returning TRUE on success.
BOOL SetFixedColumnCount(int nFixedCols = 1) //Sets the number of columns, returning TRUE on success.

4.大小与位置

int GetRowHeight(int nRow) const        //Gets the height of row nRow.
BOOL SetRowHeight(int row, int height)    //Sets the height of row nRow.
int GetColumnWidth(int nCol) const        //Gets the width of column nCol
BOOL SetColumnWidth(int col, int width)    //Sets the width of column nCol.
int GetFixedRowHeight() const            //Gets the combined height of the fixed rows.
int GetFixedColumnWidth() const            //Gets the combined width of the fixed columns.
long GetVirtualHeight() const            //Gets the combined height of all the rows.
long GetVirtualWidth() const            //Gets the combined width of all the columns.

获取cell位置及矩形

BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p);
BOOL GetCellOrigin(const CCellID& cell, LPPOINT p);

BOOL GetCellRect(int nRow, int nCol, LPRECT pRect);
BOOL GetCellRect(const CCellID& cell, LPRECT pRect);

BOOL GetTextRect(const CCellID& cell, LPRECT pRect);
BOOL GetTextRect(int nRow, int nCol, LPRECT pRect);

CSize GetTextExtent(int nRow, int nCol, LPCTSTR str);
CSize GetCellTextExtent(int nRow, int nCol);

5.行列排序

void Reorder(int From, int To); //Reorders a row ‘From‘ to row ‘To‘ 
void AllowReorderColumn(bool b=true) // Whether or not columns can be reordered 
void EnableDragRowMode(bool b=true)  //Whether or not rows can be reordered via drag and drop 
int GetLayer(int** pLayer) // Returns a pointer to an array of ints representing the current ordering of the grid. Do not forget to delete *pLayer when you are finished 
void SetLayer(int* pLayer) //Sets the ordering of the grid based on a previous saved state.

6.虚模式

void SetVirtualMode(BOOL bVirtual) //Places the grid in or out of virtual mode. 
BOOL GetVirtualMode() //Returns TRUE if the grid is in virtual mode

虚模式需要回调函数,如果不设置则会给父窗口发送GVN_GETDISPINFO通知消息

回调函数格式如下:

void SetCallbackFunc(GRIDCALLBACK pCallback, 
                     LPARAM lParam)

MFC Grid control 2.27

标签:

原文地址:http://www.cnblogs.com/wuyuan2011woaini/p/5737403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!