⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridctrl.shtml

📁 创建GRIDCTRL表格窗口及应用编程代码
💻 SHTML
📖 第 1 页 / 共 3 页
字号:
</TD><TD WIDTH="50%">Redraws the given row.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL RedrawColumn(int col)</FONT></PRE>
</TD><TD WIDTH="50%">Redraws the given column.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">CCellRange GetCellRange()</FONT></PRE>
</TD><TD WIDTH="50%">Gets the range of cells for the entire grid.
See also <a href="GridCtrl.shtml#CCellRange">CCellRange<a>.</TD>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void SetSelectedRange(const CCellRange&amp; Range,&nbsp;
                      BOOL bForceRepaint = FALSE);</FONT></PRE>
</TD><TD WIDTH="50%">Sets the range of selected cells.
See also <a href="GridCtrl.shtml#CCellRange">CCellRange<a>.</TD>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void SetSelectedRange(int nMinRow, int nMinCol, &nbsp;
                      int nMaxRow, int nMaxCol, &nbsp;
                      BOOL bForceRepaint = FALSE);</FONT></PRE>
</TD><TD WIDTH="50%">Sets the range of selected cells.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(int nRow, int nCol)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given row and column is valid.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(const CCellID&amp; cell)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given cell is valid.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(const CCellRange&amp; range)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given cell range is valid.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">CCellID GetNextItem(CCellID&amp; cell, int nFlags) const</FONT></PRE>
</TD><TD WIDTH="50%">Searches for a cell that has the specified properties and that bears the 
specified relationship to a given item. (See also CListCtrl::GetNextItem and
<a href="GridCtrl.shtml#CellSearch">Cell Searching options</a>)</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SortTextItems(int nCol, BOOL bAscending)</FONT></PRE>
</TD><TD WIDTH="50%">Sorts the grid on the given column based on cell text.
Returns TRUE on success.</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, &nbsp;
              BOOL bAscending, LPARAM data = 0)</FONT></PRE>
</TD><TD WIDTH="50%">Sorts the grid on the given column using the supplied
compare function pfnCompare. See CListCtrl::SortItems for information in the
form of this function. Returns TRUE on success.</td>
</TR>

</table>

<h3><a name="Printing">Printing</a></h3>

<TABLE CELLSPACING=0 WIDTH="90%">

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void Print()</FONT></PRE>
</TD><TD WIDTH="50%">Prints the grid control on the user selected device. 
(Useful where the control is used in a dialog)</td>
</TR>

<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnBeginPrinting.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnPrint.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnEndPrinting.</td>
</TR>

</table>

<h3><a name="Structures">Structures and defines</a></h3>

<p><a name="CCellID">The <b>CCellID</b> class<a>. This is a handy helper class used 
to reference individual cells. All members are public. This class is
adapted from Joe Willcoxsons original implementation.

<PRE><FONT COLOR="#990000">class CCellID
{    
public:
    int row, col; // The zero based row and column of the cell.

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

    int IsValid();
    int operator==(const CCellID& rhs);
    int operator!=(const CCellID& rhs);
}
</FONT></PRE>

<p><a name="CCellRange">The <b>CCellRange</b> class<a>. This is a handy helper class used 
to reference cell ranges. This class is adapted from Joe Willcoxsons original 
implementation.

<PRE><FONT COLOR="#990000">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;
    int  InRange(int row, int col) const;       // Is the row/col in the range?
    int  InRange(const CCellID& cellID) const;  // is the cell in the range?
	
    CCellID  GetTopLeft() const;                // Get topleft cell in range
    CCellRange Intersect(const CCellRange& rhs) const;&nbsp;
                                                // Returns the intersection of
                                                // two cell ranges

    int GetMinRow() const;                      // Self explanatory
    void SetMinRow(int minRow);
    int GetMinCol() const;
    void SetMinCol(int minCol);
    int GetMaxRow() const;
    void SetMaxRow(int maxRow);
    int GetMaxCol() const;
    void SetMaxCol(int maxCol);

    int GetRowSpan() const;                    // Number of rows spanned
    int GetColSpan() const;                    // Number of columns spanned
	
    int  operator==(const CCellRange& rhs);
    int  operator!=(const CCellRange& rhs);
}
</FONT></PRE>

<p>
<a name="GV_ITEM">The GV_ITEM structure<a>. This structure is used for Get/SetItem calls.

<PRE><FONT COLOR="#990000">typedef struct _GV_ITEM {
        int     row,col;   // Row and Column of item
        UINT    mask;      // Mask for use in getting/setting cell data
        UINT    state;     // cell state (focus/hilighted etc)
        UINT    nFormat;   // Format of cell. Default imaplentation used CDC::DrawText formats
        CString szText;    // Text in cell
        int     iImage;    // index of the list view item抯 icon
        LPARAM lParam;     // 32-bit value to associate with item
} GV_ITEM;</FONT></PRE>


<a name="GVL_Values">Grid line selection</a>
<PRE><FONT COLOR="#990000">GVL_NONE       - No grid lines
GVL_HORZ       - Horizontal lines only
GVL_VERT       - Vertical lines only
GVL_BOTH       - Both vertical and horizontal lines
</FONT></PRE>

<a name="CellMask">Cell data mask</a>
<PRE><FONT COLOR="#990000">GVIF_TEXT       - Cell text will be accessed
GVIF_IMAGE      - Cell image number will be accessed
GVIF_PARAM      - Cell user data (lParam) will be accessed
GVIF_STATE      - Cell state will be accessed
GVIF_FORMAT     - Cell format field will be accessed
</FONT></PRE>

<a name="CellState">Cell states</a>
<PRE><FONT COLOR="#990000">GVIS_FOCUSED      - Cell has focus
GVIS_SELECTED     - Cell is selected
GVIS_DROPHILITED  - Cell is drop highlighted
</FONT></PRE>

<a name="CellSearch">Cell Searching options</a>
<PRE><FONT COLOR="#990000">GVNI_FOCUSED      - Search for focus cell
GVNI_SELECTED     - Search for selected cells
GVNI_DROPHILITED  - Search for drop highlighted cells

GVNI_ABOVE        - Search above initial cell
GVNI_BELOW        - Search below initial cell
GVNI_TOLEFT       - Search to the left of the initial cell
GVNI_TORIGHT      - Search to the right of the initial cell
</FONT></PRE>

<h3><a name="Overrides">Protected overridable functions</a></h3>

<p> These functions have been made virtual to aid extensiblity.

<p><b>Printing</b> - called in OnPrint.
<PRE><FONT COLOR="#990000">virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo); 
virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
</FONT></PRE>

<p><b>Drag n' drop</b>
<PRE><FONT COLOR="#990000">
virtual CImageList* CreateDragImage(CPoint *pHotSpot) - No longer necessary but I 
                                                        thought the code was cool so
                                                        kept it :).
</FONT></PRE>

<p><b>Mouse Clicks</b>
<PRE><FONT COLOR="#990000">virtual void OnFixedColumnClick(CCellID&amp; cell);
virtual void OnFixedRowClick(CCellID&amp; cell);
</FONT></PRE>

<p><b>Editing</b>
<PRE><FONT COLOR="#990000">virtual void OnEditCell(int nRow, int nCol, UINT nChar)     - Starting edit
virtual void OnEndEditCell(int nRow, int nCol, CString str) - ending edit
</FONT></PRE>

<p><b>Drawing</b>
<PRE><FONT COLOR="#990000">virtual CSize GetCellExtent(int nRow, int nCol, CDC* pDC)   - Returns Size of cell
                                                              according to cell
                                                              contents.
virtual void OnDraw(CDC&amp; origDC);                           - Draws everything
virtual BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol,    - Draws Fixed cells
                           CRect rect, BOOL bEraseBk=FALSE) 
virtual BOOL DrawCell(CDC* pDC, int nRow, int nCol,         - Draws normal cells
                      CRect rect, BOOL bEraseBk=FALSE)
</FONT></PRE>

<p><b>Cleanup</b>
<PRE><FONT COLOR="#990000">virtual void EmptyCell(CGridCell* cell, int nRow, int nCol) - Performs any cleanup
                                                              necessary before removing
                                                              cells
</FONT></PRE>


<h3><a name="Acknowledgements">Acknowledgements</a></h3>

<p>This would not have been possible without the following authors
making their code freely available:
<ul>
<li><a href="mailto:chinajoe@aol.com">Joe Willcoxson</a>: Joe's original code spurred this project on, and
provided the basic structure of this grid control.</li>

<li><a href="keithr@europa.com">Keith Rule</a>: Keith provided a neat CMemDC
class to make flicker free display simple, and provided sample OLE copy/paste/drag/drop
code.</li>

<li><a href="rreddy@braintech.com">Ravi Reddy</a>: I used a derivation of Ravi's listview 
printing code.</li>

<li><a href="zafir@dsp.com">Zafir Anjum</a>: Provided the starting point for my CInPlaceEdit, 
and the sorting routines, and is the site maintainer for The MFC Programmers Sourcebook, 
at <A HREF="http://www.codeguru.com">www.codeguru.com</a>. Zafir has done a great
job of allowing devlopers to swap code and learn from each other. 

<li>All those who contribute to the <a href="http://www.codeguru.com">MFC Programmers Sourcebook</a>:
Without you all I would not have been able to write this.</li>

<li>All those who sent in bug reports, suggestions and encouragement.</li>
</ul>

<h3><a name="History">History</a></h3>

<p>Version
<TABLE CELLSPACING=0 WIDTH="90%">

<TR VALIGN=TOP>
<TD WIDTH="30%">&nbsp;&nbsp;&nbsp;&nbsp; 1.00 &nbsp;&nbsp;&nbsp; 20 Feb 1998</td>
<TD WIDTH="70%">First release version.</td>
</TR>

<TR VALIGN=TOP>
<TD WIDTH="30%">&nbsp;&nbsp;&nbsp;&nbsp; 1.01 &nbsp;&nbsp;&nbsp; 24 Feb 1998</td>
<TD WIDTH="70%">Memory leak fix (Jens Bohlmann <bohly@jelo.de>)<br>
                Mistype in CMemDC.h - Claus Arend-Schneider<br>
                Bug in GetSelectedCount - Lyn Newton<br></td>
</TR>

<TR VALIGN=TOP>
<TD WIDTH="30%">&nbsp;&nbsp;&nbsp;&nbsp; 1.02 &nbsp;&nbsp;&nbsp; 4 Mar 1998</td>
<TD WIDTH="70%">Scrolling a little neater (less dead area)<br>
                Cell selection via OnTimer correctly updates Focus cell</td>
</TR>

<a name="New"></a>

<TR VALIGN=TOP>
<TD WIDTH="30%">&nbsp;&nbsp;&nbsp;&nbsp; 1.03 &nbsp;&nbsp;&nbsp; 31 Mar 1998</td>
<TD WIDTH="70%">OnEditCopy, OnEditCut and OnEditPaste clipboard functions added.<br>
                Ctrl-X,Ctrl-C and Ctrl-V now initiate clipboard cut, copy and paste.<br>
                Support for OLE drag and drop.<br>
                Support for Microsoft intellimouse.<br>
                "DeleteContents" changed to "DeleteAllItems".<br>
                ExpandRowsToFit and ExpandColumnsToFit added.<br>
                Added SetHeaderSort and GetHeaderSort.<br>
                ExpandRowsToFit and ExpandColumnsToFit added.<br>
                Selected cell IDs now stored in a map instead of an array.<br>
                Scrolling and scroll selection tweaked a little.<br>
                Several minor bugs fixed.<br>
                LVN_ENDLABELEDIT now handled using ON_NOTIFY_REFLECT_EX so the parent can
handle it too.<br>
                GetItemText() now public.<br>
</td>
</TR>

</table>

<P>Updated: March 31, 1998.


<P><HR>

<!-- Contact details -->
<TABLE BORDER=0 WIDTH="100%">
<TR>

<TD WIDTH="33%"><FONT SIZE=-1><A HREF="http://www.codeguru.com">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1997 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>

</TR>
</TABLE>

<!-- Counter -->
<CENTER><FONT SIZE=-2><!--#exec cgi="../cgi/counters/counter.cgi"--></FONT></CENTER>

</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -