📄 gridctrl.h
字号:
void SetListMode(BOOL bEnableListMode = TRUE);
BOOL GetListMode() const { return m_bListMode; }
void SetSingleRowSelection(BOOL bSing = TRUE) { m_bSingleRowSelection = bSing; }
BOOL GetSingleRowSelection() { return m_bSingleRowSelection & m_bListMode; }
void SetSingleColSelection(BOOL bSing = TRUE) { m_bSingleColSelection = bSing; }
BOOL GetSingleColSelection() { return m_bSingleColSelection; }
void EnableSelection(BOOL bEnable = TRUE) { ResetSelectedRange(); m_bEnableSelection = bEnable; ResetSelectedRange(); }
BOOL IsSelectable() const { return m_bEnableSelection; }
void SetFixedColumnSelection(BOOL bSelect) { m_bFixedColumnSelection = bSelect;}
BOOL GetFixedColumnSelection() { return m_bFixedColumnSelection; }
void SetFixedRowSelection(BOOL bSelect) { m_bFixedRowSelection = bSelect; }
BOOL GetFixedRowSelection() { return m_bFixedRowSelection; }
void EnableDragAndDrop(BOOL bAllow = TRUE) { m_bAllowDragAndDrop = bAllow; }
BOOL GetDragAndDrop() const { return m_bAllowDragAndDrop; }
void SetRowResize(BOOL bResize = TRUE) { m_bAllowRowResize = bResize; }
BOOL GetRowResize() const { return m_bAllowRowResize; }
void SetColumnResize(BOOL bResize = TRUE) { m_bAllowColumnResize = bResize; }
BOOL GetColumnResize() const { return m_bAllowColumnResize; }
void SetHeaderSort(BOOL bSortOnClick = TRUE) { m_bSortOnClick = bSortOnClick; }
BOOL GetHeaderSort() const { return m_bSortOnClick; }
void SetHandleTabKey(BOOL bHandleTab = TRUE) { m_bHandleTabKey = bHandleTab; }
BOOL GetHandleTabKey() const { return m_bHandleTabKey; }
void SetDoubleBuffering(BOOL bBuffer = TRUE) { m_bDoubleBuffer = bBuffer; }
BOOL GetDoubleBuffering() const { return m_bDoubleBuffer; }
void EnableTitleTips(BOOL bEnable = TRUE) { m_bTitleTips = bEnable; }
BOOL GetTitleTips() { return m_bTitleTips; }
void SetSortColumn(int nCol);
int GetSortColumn() const { return m_nSortColumn; }
void SetSortAscending(BOOL bAscending) { m_bAscending = bAscending; }
BOOL GetSortAscending() const { return m_bAscending; }
void SetTrackFocusCell(BOOL bTrack) { m_bTrackFocusCell = bTrack; }
BOOL GetTrackFocusCell() { return m_bTrackFocusCell; }
void SetFrameFocusCell(BOOL bFrame) { m_bFrameFocus = bFrame; }
BOOL GetFrameFocusCell() { return m_bFrameFocus; }
void SetAutoSizeStyle(int nStyle = GVS_BOTH) { m_nAutoSizeColumnStyle = nStyle; }
int GetAutoSizeStyle() { return m_nAutoSizeColumnStyle; }
void EnableHiddenColUnhide(BOOL bEnable = TRUE){ m_bHiddenColUnhide = bEnable; }
BOOL GetHiddenColUnhide() { return m_bHiddenColUnhide; }
void EnableHiddenRowUnhide(BOOL bEnable = TRUE){ m_bHiddenRowUnhide = bEnable; }
BOOL GetHiddenRowUnhide() { return m_bHiddenRowUnhide; }
void EnableColumnHide(BOOL bEnable = TRUE) { m_bAllowColHide = bEnable; }
BOOL GetColumnHide() { return m_bAllowColHide; }
void EnableRowHide(BOOL bEnable = TRUE) { m_bAllowRowHide = bEnable; }
BOOL GetRowHide() { return m_bAllowRowHide; }
///////////////////////////////////////////////////////////////////////////////////
// default Grid cells. Use these for setting default values such as colors and fonts
///////////////////////////////////////////////////////////////////////////////////
public:
CGridCellBase* GetDefaultCell(BOOL bFixedRow, BOOL bFixedCol) const;
///////////////////////////////////////////////////////////////////////////////////
// Grid cell Attributes
///////////////////////////////////////////////////////////////////////////////////
public:
CGridCellBase* GetCell(int nRow, int nCol) const; // Get the actual cell!
void SetModified(BOOL bModified = TRUE, int nRow = -1, int nCol = -1);
BOOL GetModified(int nRow = -1, int nCol = -1);
BOOL IsCellFixed(int nRow, int nCol);
BOOL SetItem(const GV_ITEM* pItem);
BOOL GetItem(GV_ITEM* pItem);
BOOL SetItemText(int nRow, int nCol, LPCTSTR str);
// The following was virtual. If you want to override, use
// CGridCellBase-derived class's GetText() to accomplish same thing
CString GetItemText(int nRow, int nCol) const;
// EFW - 06/13/99 - Added to support printf-style formatting codes.
// Also supports use with a string resource ID
#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 210)
BOOL SetItemTextFmt(int nRow, int nCol, LPCTSTR szFmt, ...);
BOOL SetItemTextFmtID(int nRow, int nCol, UINT nID, ...);
#endif
BOOL SetItemData(int nRow, int nCol, LPARAM lParam);
LPARAM GetItemData(int nRow, int nCol) const;
BOOL SetItemImage(int nRow, int nCol, int iImage);
int GetItemImage(int nRow, int nCol) const;
BOOL SetItemState(int nRow, int nCol, UINT state);
UINT GetItemState(int nRow, int nCol) const;
BOOL SetItemFormat(int nRow, int nCol, UINT nFormat);
UINT GetItemFormat(int nRow, int nCol) const;
BOOL SetItemBkColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
COLORREF GetItemBkColour(int nRow, int nCol) const;
BOOL SetItemFgColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
COLORREF GetItemFgColour(int nRow, int nCol) const;
BOOL SetItemFont(int nRow, int nCol, const LOGFONT* lf);
const LOGFONT* GetItemFont(int nRow, int nCol);
BOOL IsItemEditing(int nRow, int nCol);
BOOL SetCellType(int nRow, int nCol, CRuntimeClass* pRuntimeClass);
BOOL SetDefaultCellType( CRuntimeClass* pRuntimeClass);
///////////////////////////////////////////////////////////////////////////////////
// Operations
///////////////////////////////////////////////////////////////////////////////////
public:
int InsertColumn(LPCTSTR strHeading, UINT nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE,
int nColumn = -1);
int InsertRow(LPCTSTR strHeading, int nRow = -1);
BOOL DeleteColumn(int nColumn);
BOOL DeleteRow(int nRow);
BOOL DeleteNonFixedRows();
BOOL DeleteAllItems();
void ClearCells(CCellRange Selection);
BOOL AutoSizeRow(int nRow, BOOL bResetScroll = TRUE);
BOOL AutoSizeColumn(int nCol, UINT nAutoSizeStyle = GVS_DEFAULT, BOOL bResetScroll = TRUE);
void AutoSizeRows();
void AutoSizeColumns(UINT nAutoSizeStyle = GVS_DEFAULT);
void AutoSize(UINT nAutoSizeStyle = GVS_DEFAULT);
void ExpandColumnsToFit(BOOL bExpandFixed = TRUE);
void ExpandLastColumn();
void ExpandRowsToFit(BOOL bExpandFixed = TRUE);
void ExpandToFit(BOOL bExpandFixed = TRUE);
void Refresh();
void AutoFill(); // Fill grid with blank cells
void EnsureVisible(CCellID &cell) { EnsureVisible(cell.row, cell.col); }
void EnsureVisible(int nRow, int nCol);
BOOL IsCellVisible(int nRow, int nCol);
BOOL IsCellVisible(CCellID cell);
BOOL IsCellEditable(int nRow, int nCol) const;
BOOL IsCellEditable(CCellID &cell) const;
BOOL IsCellSelected(int nRow, int nCol) const;
BOOL IsCellSelected(CCellID &cell) const;
// SetRedraw stops/starts redraws on things like changing the # rows/columns
// and autosizing, but not for user-intervention such as resizes
void SetRedraw(BOOL bAllowDraw, BOOL bResetScrollBars = FALSE);
BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL);
BOOL RedrawRow(int row);
BOOL RedrawColumn(int col);
#ifndef _WIN32_WCE
BOOL Save(LPCTSTR filename, TCHAR chSeparator = _T(','));
BOOL Load(LPCTSTR filename, TCHAR chSeparator = _T(','));
#endif
///////////////////////////////////////////////////////////////////////////////////
// Cell Ranges
///////////////////////////////////////////////////////////////////////////////////
public:
CCellRange GetCellRange() const;
CCellRange GetSelectedCellRange() const;
void SetSelectedRange(const CCellRange& Range, BOOL bForceRepaint = FALSE, BOOL bSelectCells = TRUE);
void SetSelectedRange(int nMinRow, int nMinCol, int nMaxRow, int nMaxCol,
BOOL bForceRepaint = FALSE, BOOL bSelectCells = TRUE);
BOOL IsValid(int nRow, int nCol) const;
BOOL IsValid(const CCellID& cell) const;
BOOL IsValid(const CCellRange& range) const;
///////////////////////////////////////////////////////////////////////////////////
// Clipboard, drag and drop, and cut n' paste operations
///////////////////////////////////////////////////////////////////////////////////
#ifndef GRIDCONTROL_NO_CLIPBOARD
virtual void CutSelectedText();
virtual COleDataSource* CopyTextFromGrid();
virtual BOOL PasteTextToGrid(CCellID cell, COleDataObject* pDataObject, BOOL bSelectPastedCells=TRUE);
#endif
#ifndef GRIDCONTROL_NO_DRAGDROP
public:
virtual void OnBeginDrag();
virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
virtual void OnDragLeave();
virtual BOOL OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
#endif
#ifndef GRIDCONTROL_NO_CLIPBOARD
virtual void OnEditCut();
virtual void OnEditCopy();
virtual void OnEditPaste();
#endif
virtual void OnEditSelectAll();
///////////////////////////////////////////////////////////////////////////////////
// Misc.
///////////////////////////////////////////////////////////////////////////////////
public:
CCellID GetNextItem(CCellID& cell, int nFlags) const;
BOOL SortItems(int nCol, BOOL bAscending, LPARAM data = 0);
BOOL SortTextItems(int nCol, BOOL bAscending, LPARAM data = 0);
BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data = 0);
void SetCompareFunction(PFNLVCOMPARE pfnCompare);
// in-built sort functions
static int CALLBACK pfnCellTextCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
static int CALLBACK pfnCellNumericCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
///////////////////////////////////////////////////////////////////////////////////
// Printing
///////////////////////////////////////////////////////////////////////////////////
#if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
public:
void Print(CPrintDialog* pPrntDialog = NULL);
// EFW - New printing support functions
void EnableWysiwygPrinting(BOOL bEnable = TRUE) { m_bWysiwygPrinting = bEnable; }
BOOL GetWysiwygPrinting() { return m_bWysiwygPrinting; }
void SetShadedPrintOut(BOOL bEnable = TRUE) { m_bShadedPrintOut = bEnable; }
BOOL GetShadedPrintOut(void) { return m_bShadedPrintOut; }
// Use -1 to have it keep the existing value
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);
///////////////////////////////////////////////////////////////////////////////////
// Printing overrides for derived classes
///////////////////////////////////////////////////////////////////////////////////
public:
virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
#endif // #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
// Implementation
public:
virtual ~CGridCtrl();
protected:
BOOL RegisterWindowClass();
BOOL Initialise();
void SetupDefaultCells();
LRESULT SendMessageToParent(int nRow, int nCol, int nMessage) const;
LRESULT SendDisplayRequestToParent(GV_DISPINFO* pDisplayInfo) const;
LRESULT SendCacheHintToParent(const CCellRange& range) const;
BOOL InvalidateCellRect(const int row, const int col);
BOOL InvalidateCellRect(const CCellID& cell);
BOOL InvalidateCellRect(const CCellRange& cellRange);
void EraseBkgnd(CDC* pDC);
BOOL GetCellRangeRect(const CCellRange& cellRange, LPRECT lpRect);
BOOL SetCell(int nRow, int nCol, CGridCellBase* pCell);
int SetMouseMode(int nMode) { int nOldMode = m_MouseMode; m_MouseMode = nMode; return nOldMode; }
int GetMouseMode() const { return m_MouseMode; }
BOOL MouseOverRowResizeArea(CPoint& point);
BOOL MouseOverColumnResizeArea(CPoint& point);
CCellID GetTopleftNonFixedCell(BOOL bForceRecalculation = FALSE);
CCellRange GetUnobstructedNonFixedCellRange(BOOL bForceRecalculation = FALSE);
CCellRange GetVisibleNonFixedCellRange(LPRECT pRect = NULL, BOOL bForceRecalculation = FALSE);
CCellRange GetVisibleFixedCellRange(LPRECT pRect = NULL, BOOL bForceRecalculation = FALSE);
BOOL IsVisibleVScroll() { return ( (m_nBarState & GVL_VERT) > 0); }
BOOL IsVisibleHScroll() { return ( (m_nBarState & GVL_HORZ) > 0); }
void ResetSelectedRange();
void ResetScrollBars();
void EnableScrollBars(int nBar, BOOL bEnable = TRUE);
int GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);
BOOL SortTextItems(int nCol, BOOL bAscending, int low, int high);
BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data,
int low, int high);
CPoint GetPointClicked(int nRow, int nCol, const CPoint& point);
void ValidateAndModifyCellContents(int nRow, int nCol, LPCTSTR strText);
// Overrrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGridCtrl)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
protected:
#if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
// Printing
virtual void PrintFixedRowCells(int nStartColumn, int nStopColumn, int& row, CRect& rect,
CDC *pDC, BOOL& bFirst);
virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintRowButtons(CDC *pDC, CPrintInfo* /*pInfo*/);
#endif
#ifndef GRIDCONTROL_NO_DRAGDROP
// Drag n' drop
virtual CImageList* CreateDragImage(CPoint *pHotSpot); // no longer necessary
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -