📄 gridctrl.h
字号:
//{{AFX_VIRTUAL(CGridCtrl)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
public:
virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
CGridCell* GetCell(int nRow, int nCol) const;
BOOL SetCell(int nRow, int nCol, CGridCell* pCell);
// Implementation
public:
virtual ~CGridCtrl();
protected:
BOOL RegisterWindowClass();
BOOL SendMessageToParent(int nRow, int nCol, int nMessage,CString sTxt);
BOOL InvalidateCellRect(const CCellID& cell);
BOOL InvalidateCellRect(const CCellRange& cellRange);
void EraseBkgnd(CDC* pDC);
BOOL GetCellRangeRect(const CCellRange& cellRange, LPRECT lpRect) const;
int SetMouseMode(int nMode);
int GetMouseMode() const;
CCellID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE) const;
CCellID GetTopleftNonFixedCell() const;
CCellRange GetUnobstructedNonFixedCellRange() const;
CCellRange GetVisibleNonFixedCellRange(LPRECT pRect = NULL) const;
void ResetSelectedRange();
void ResetScrollBars();
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);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTimeGridCtrl)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
protected:
// Printing
virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
// Drag n' drop
virtual CImageList* CreateDragImage(CPoint *pHotSpot); // no longer necessary
// Mouse Clicks
virtual void OnFixedColumnClick(CCellID& cell);
virtual void OnFixedRowClick(CCellID& cell);
// Editing
virtual CSize GetCellExtent(int nRow, int nCol, CDC* pDC);
// Drawing
virtual void OnDraw(CDC* pDC);
virtual BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
virtual BOOL DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
// GridCell Creation and Cleanup
virtual CGridCell* CreateCell(int nRow, int nCol);
virtual void EmptyCell(CGridCell* pCell, int nRow, int nCol);
// Attributes
public:
CView* m_pParentWnd;
int m_nHeaderHeight,m_nFootHeight,m_nLeft,m_nRight,m_nTop,
m_nBottom,m_nHeaderGap;
CPoint m_nLastPoint;
CToolTipCtrl* m_pToolTip;
CRect m_rectSearch;
protected:
// General attributes
COLORREF m_crTextColour, m_crTextBkColour, m_crBkColour,
m_crFixedTextColour, m_crFixedBkColour, m_crGridColour;
COLORREF m_crWindowText, m_crWindowColour, m_cr3DFace,m_crShadow;
int m_nGridLines;
BOOL m_bEditable,m_bModified,m_bAllowDragAndDrop,
m_bListMode,m_bAllowDraw,m_bEnableSelection,
m_bSortOnClick,m_bHandleTabKey,m_bDoubleBuffer,m_bTitleTips;
// Cell size details
int m_nRows,m_nFixedRows,m_nCols,m_nFixedCols,m_nMargin,
m_nDefCellWidth, m_nDefCellHeight,m_nVScrollMax, m_nHScrollMax,
m_MouseMode;
CUIntArray m_arRowHeights,m_arColWidths;
// Fonts and images
LOGFONT m_Logfont;
CFont m_PrinterFont,m_Font;
CImageList* m_pImageList;
CTypedPtrArray<CObArray, GRID_ROW*> m_RowData;
CPoint m_LeftClickDownPoint, m_LastMousePoint;
CCellID m_LeftClickDownCell, m_SelectionStartCell,m_idCurrentCell,m_LastDragOverCell;
int m_nTimerID,m_nTimerInterval,m_nRowsPerWheelNotch,m_nResizeCaptureRange;
BOOL m_bAllowRowResize, m_bAllowColumnResize,m_bMustUninitOLE;
// Printing information
CSize m_CharSize,m_LogicalPageSize,m_PaperSize;
int m_nPageHeight,m_bAscending,m_SortColumn;
CMap<DWORD,DWORD, CCellID, CCellID&> m_SelectedCellMap, m_PrevSelectedCellMap;
protected:
void SelectAllCells();
void SelectColumns(CCellID currentCell);
void SelectRows(CCellID currentCell);
void SelectCells(CCellID currentCell);
void OnSelecting(const CCellID& currentCell);
// Generated message map functions
//{{AFX_MSG(CGridCtrl)
afx_msg void OnPaint();
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg UINT OnGetDlgCode();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnSysColorChange();
afx_msg void OnCaptureChanged(CWnd *pWnd);
//}}AFX_MSG
#if _MFC_VER >= 0x0421
afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
#endif
afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam);
afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMH, LRESULT *pResult);
DECLARE_MESSAGE_MAP()
enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW,
MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS,
MOUSE_OVER_ROW_DIVIDE, MOUSE_SIZING_ROW,
MOUSE_OVER_COL_DIVIDE, MOUSE_SIZING_COL,
MOUSE_PREPARE_EDIT, MOUSE_PREPARE_DRAG, MOUSE_DRAGGING};
};
inline CGridCell* CGridCtrl::GetCell(int nRow, int nCol) const
{
if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return NULL;
GRID_ROW* pRow = m_RowData[nRow];
if (!pRow) return NULL;
return pRow->GetAt(nCol);
}
inline BOOL CGridCtrl::SetCell(int nRow, int nCol, CGridCell* pCell)
{
if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return FALSE;
GRID_ROW* pRow = m_RowData[nRow];
if (!pRow) return FALSE;
pRow->SetAt(nCol, pCell);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -