现在的位置: 首页 > 综合 > 正文

CGridCtrl

2013年08月13日 ⁄ 综合 ⁄ 共 3738字 ⁄ 字号 评论关闭

 class
 CGridCtrl : 
public
 CWnd



{

    

    

//
  1. CGridCtrl类的构造函数


    

    CGridCtrl(

int
 nRows 
=
 
0

int
 nCols 
=
 
0

int
 nFixedRows 
=
 
0

int
 nFixedCols 
=
 
0
);

    

    BOOL Create(

const
 RECT
&
 rect, CWnd
*
 parent, UINT nID,

        

        DWORD dwStyle 

=
 WS_CHILD 
|
 WS_BORDER 
|
 WS_TABSTOP 
|
 WS_VISIBLE);


    

    

//
  2. 表格行、列数方面的函数


    

    BOOL SetRowCount(

int
 nRows);                         
//
设置表的行数


        

    BOOL SetColumnCount(

int
 nCols);                      
//
设置表的列数


        

    BOOL SetFixedRowCount(

int
 nFixedRows 
=
 
1
);            
//
设置表的固定行数


        

    BOOL SetFixedColumnCount(

int
 nFixedCols 
=
 
1
);         
//
设置表的固定列数


        

    

int
  GetFixedRowCount() 
const
;                        
//
  取表的固定行数


        

    

int
  GetFixedColumnCount() 
const
;                     
//
取表的固定列数


        

    ……

        

    

//
  3. 表格尺寸大小方面的函数


        

    BOOL SetRowHeight(

int
 row, 
int
 height);                
//
设置表格单元的高度


        

    BOOL SetColumnWidth(

int
 col, 
int
 height);              
//
设置表格单元的宽度


        

    

int
 GetRowHeight(
int
 nRow) 
const
;                      
//
获取表格单元的高度


        

    

int
 GetColumnWidth(
int
 nCol) 
const
;                    
//
获取表格单元的宽度


        

    

void
 AutoSize();                          
//
对表格单元的高度与宽度进行自动设置


        

    ……

        

    

//
  4. 表格显示与特征方面的函数


        

    

void
 SetImageList(CImageList
*
 pList);                    
//
设置列表图标


    

    

void
 SetEditable(BOOL bEditable 
=
 TRUE);                 
//
设置表格的编辑状态


        

    BOOL SetColumnType(

int
 nCol, 
int
 nType);                 
//
设置表格的列状态


        

    ……

        

    

//
 5. 颜色方面的函数


        

    

void
 SetTextColor(COLORREF clr);                    
//
设置输入表格的文本颜色


        

    

void
 SetTextBkColor(COLORREF clr);               
//
设置可供输入文本的表格颜色


        

    

void
 SetFixedTextColor(COLORREF clr);            
//
设置输入固定表格的文本颜色


        

    

void
 SetFixedBkColor(COLORREF clr);              
//
设置固定表格颜色


        

    ……

        

    

//
 6. 表格信息函数


        

    BOOL SetItem(

const
 GV_ITEM
*
 pItem);              
//
 向表格中输入信息


        

    BOOL SetItemText(

int
 nRow, 
int
 nCol, LPCTSTR str);    
//
向某一单元表格中输入文本


        

    BOOL SetItemImage(

int
 nRow, 
int
 nCol, 
int
 iImage);     
//
在某一单元表格中设置图标


        

    ……

        

    

//
 7. 编辑方面的函数


        

    

virtual
 
void
 OnEditCell(
int
 nRow, 
int
 nCol, UINT nChar)     
//
开始对表格进行编辑


        

    

virtual
 
void
 OnEndEditCell(
int
 nRow, 
int
 nCol, CString str)   
//
结束对表格编辑


        

    ……

        

    

//
 8. 表格打印函数


        

    

void
 Print();                                       
//
打印表格


        

    ……

        

}


;

CGridCtrl类的构造函数形式如下:

CGridCtrl::CGridCtrl(
int
 nRows, 
int
 nCols, 
int
 nFixedRows, 
int
 nFixedCols)



{


    m_crWindowText       

=
 ::GetSysColor(COLOR_WINDOWTEXT);


    m_crWindowColour     

=
 ::GetSysColor(COLOR_WINDOW);


    m_cr3DFace           

=
 ::GetSysColor(COLOR_3DFACE);


    m_nRows              

=
 
0
;         
//
初始电子表格的行数




    m_nCols               

=
 
0
;        
//
初始电子表格的列数




    m_nFixedRows          

=
 
0
;        
//
初始化固定表格的行数




    m_nFixedCols           

=
 
0
;       
//
初始化固定表格的列数




    m_bEditable            

=
 TRUE;    
//
初始化表格为可编辑状态




     ……


       

//
初始化设置表格的行列数




    SetRowCount(nRows);


    SetColumnCount(nCols);


    SetFixedRowCount(nFixedRows);


    SetFixedColumnCount(nFixedCols);


     

//
 初始化表格的背景颜色及输入表格的文本颜色




    SetTextColor(m_crWindowText);


    SetTextBkColor(m_crWindowColour);


    SetFixedTextColor(m_crWindowText);


    SetFixedBkColor(m_cr3DFace);


    ……      

}


对表格中所输入信息属性的描述,是通过定义一结构体函数来实现,该结构体函数形式如下:

typedef 
struct
 _GV_ITEM 

{

    

    

int
     row,col;            
//
 输入信息的位置


    

    UINT    mask;                

//
输入信息的灰度值


    

    UINT    state;                

//
 表格单元的状态


    

    UINT    nFormat;            

//
 信息的输入形式


    

    CString szText;                

//
 输入表格单元的文本


    

}


 GV_ITEM;

将CGridCtrl类与以下类结合起来,即可构造成在其上可进行编辑和修改的电子
表格,这些类分别为:

1.用于单元表格范围的两个类:CCellRange[2]类和CCellID[3]类;

2.单元表格状态属性的类:CGridCell[4]类;

3.对表格进行编辑的两个类:CInplaceEdit[5]类和CInplaceList[6]类;

抱歉!评论已关闭.