📄 gridctrl.shtml
字号:
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
COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
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_BKCLR - Cell background colour will be accessed
GVIF_FGCLR - Cell foreground colour 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
GVIS_READONLY - Cell is read-only and cannot be edited
</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>
<a name="Messages">Notification messages</a>
<PRE><FONT COLOR="#990000">GVN_BEGINDRAG - Sent when dragging starts
GVN_BEGINLABELEDIT - Sent when inplace editing starts
GVN_ENDLABELEDIT - Sent when inplace editing stops
</FONT></PRE>
<p>These messages are exactly the same as their LVN_... counterparts, except
they use an NM_GRIDVIEW structure:
<PRE><FONT COLOR="#990000">typedef struct tagNM_GRIDVIEW {
NMHDR hdr;
int iRow;
int iColumn;
} NM_GRIDVIEW;
</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& cell);
virtual void OnFixedRowClick(CCellID& 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& 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="Clipboard">Clipboard</a></h3>
<p>A number of Clipboard functions have been included.<br>
<TABLE CELLSPACING=0 WIDTH="90%">
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEditCut()</FONT></PRE>
</TD><TD WIDTH="50%">Copies contents of selected cells to clipboard and deletes the
contents of the selected cells. (Ctrl-X)</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEditCopy()</FONT></PRE>
</TD><TD WIDTH="50%">Copies contents of selected cells to clipboard. (Ctrl-C)</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEditPaste()</FONT></PRE>
</TD><TD WIDTH="50%">Pastes the contents of the clipboard to the grid. (Ctrl-V)</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEditSelectAll()</FONT></PRE>
</TD><TD WIDTH="50%">Not actually a clipboard function, but handy nevertheless.
This routine selects all cells in the grid. (Ctrl-A)</td>
</TR>
</table>
<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, improvements and encouragement.</li>
</ul>
<h3><a name="History">History</a></h3>
<p>Version
<TABLE CELLSPACING=0 WIDTH="90%">
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.00 20 Feb 1998</td>
<TD WIDTH="70%">First release version.</td>
</TR>
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.01 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%"> 1.02 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>
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.03 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>
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.04 5 April 1998</td>
<TD WIDTH="70%">Added Ctrl-A = OnEditSelectAll. <br>
Fixed CGridDropTarget double register problem<br>
Minor bug in CopyTextFromGrid (assert on empty string) fixed.<br>
Cleaned up reponse to m_bEditable (OnDrop and Ctrl-X disabled).
</td>
</tr>
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.05 10 March 1998</td>
<TD WIDTH="70%">Memory leak fixed. (Yuheng Zhao)<br>
Changed OLE initialisation (Carlo Comino)<br>
Added separate fore + background cell colours (John Crane).<br>
ExpandToFit etc cleaned up - now decreases and increases cell sizes to
fit client area.<br>
Added notification messages for the grid's parent<br>
Added GVIS_READONLY state<br>
</td>
</tr>
<a name="New"></a>
<TR VALIGN=TOP>
<TD WIDTH="30%"> 1.06 12 March 1998</td>
<TD WIDTH="70%">Added TAB key handling (Use Get/SetHandleTabKey to toggle). (Daniela Rybarova)<br>
Intellimouse code correction for whole page scrolling (Paul Grant)<br>
Fixed 16 bit thumb track problems (now 32 bit) (Paul Grant)<br>
Fixed accelerator key problem in CInPlaceEdit (Matt Weagle)<br>
Fixed Stupid ClassWizard code parsing problem (Michael A. Barnhart)<br>
Double buffering now programmatically selectable (Use Get/SetDoubleBuffering)<br>
Workaround for win95 drag and drop registration problem<br>
Corrected UNICODE implementation of clipboard stuff<br>
Dragging and dropping from a selection onto itself no no longer causes the
cells to be emptied<br>
</td>
</tr>
</table>
<P>Updated: May 20, 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>© 1998 Zafir Anjum</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<!-- Counter -->
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -