📄 custom~1.h
字号:
#if !defined(AFX_CUSTOMGRID_H__85890F9E_7296_11D4_ACD5_00104B12129F__INCLUDED_)
#define AFX_CUSTOMGRID_H__85890F9E_7296_11D4_ACD5_00104B12129F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CustomGrid.h : header file
//
#include "CellEdit.h"
#define IDC_CELLEDIT_CONTROL 8
#define GRIDCTRL_CLASSNAME _T("CustomGrid") // Window class name
/////////////////////////////////////////////////////////////////////////////
// CCustomGrid window
#define DEFAULT_COLUMWIDTH 100
#define CR_DEFAULT_BK 0xC0C0C0 // 0xC0C0C0 为界面常用的灰色
#define CR_DEFAULT_FIXEDBK 0XFFFFA0
#define CR_DEFAULT_FIXITEM 0xFF0000
#define CR_DEFAULT_ITEM 0x0
#define DEFAULT_TEXTWRAP 5
#define DEFAULT_LINESCROLL 3
class CCustomGrid : public CWnd
{
// Construction
public:
CCustomGrid();
// Attributes
private:
CStringArray m_strItems;
CWordArray m_nColumsWidth;
UINT m_nRows, m_nColums;
long m_nFontHeight;
CFont m_Font;
UINT m_nFixedRows, m_nFixedColums;
int m_nVScrollMax, m_nHScrollMax;
bool m_bCellEditable;
LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
public:
void SetFixedRowCount( UINT row = 1 )
{ m_nFixedRows = row; if(m_nRows < m_nFixedRows) SetRowCount( row );}
UINT GetFixedRowCount( )
{ return m_nFixedRows; }
void SetFixedColumnCount( UINT colum = 0 )
{ m_nFixedColums = colum; if(m_nColums < m_nFixedColums) SetColumnCount( colum );}
UINT GetFixedColumnCount( )
{ return m_nFixedColums; }
void SetRowCount( UINT row = 10 );
UINT GetRowCount( )
{ return m_nRows; }
void SetColumnCount( UINT colum = 10, int* columwidth = NULL);
UINT GetColumnCount( )
{ return m_nColums; }
void SetItemString( int row, int colum, LPCTSTR item );
CString GetItemString( int row, int colum )
{ASSERT( row < m_nRows && colum < m_nColums); return m_strItems.GetAt(row*m_nColums + colum); }
void SetItemFont( int FontHeight = 12 );
CFont* GetItemFont( )
{ return &m_Font; }
void AppendRow()//增加一行
{ SetRowCount( GetRowCount() + 1); }
void AppendCol()//增加一列
{ SetColumnCount( GetColumnCount() + 1); }
void SetEditable(BOOL bEditable = TRUE)
{ m_bCellEditable = bEditable; }
BOOL IsEditable() const
{ return m_bCellEditable; }
void ResetScrollBars();
int GetFixedColumnWidth();
int GetFixedRowHeight();
int GetVirtualWidth();
int GetVirtualHeight();
int GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);
void DrawCell(CDC* pDC, int nRow, int nCol, CRect rect);
void DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect);
RECT GetScrolledCellRect(int Row, int Col);
CPoint GetScrolledCellFromPT(CPoint& Point);
void VisibleCell(int Row, int Column);
int MouseOverColumnResizeArea(CPoint& point);
void StartEditCell(int nRow, int nCol);
private:
int m_nMouseMode;
int m_nSizingCol;
CPoint m_OldPoint;
bool m_bCanScrollPage;
enum eMouseModes { MOUSE_NOTHING, MOUSE_OVER_COL_DIVIDE,
MOUSE_SIZING_COL
};
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCustomGrid)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCustomGrid();
// Generated message map functions
protected:
//{{AFX_MSG(CCustomGrid)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
afx_msg void OnModifyEditCell(NMHDR* pNMHDR, LRESULT* pResult);
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: keithr@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// History - 10/3/97 Fixed scrolling bug.
// Added print support.
// 25 feb 98 - fixed minor assertion bug
//
// This class implements a memory Device Context
class CMemDC : public CDC
{
public:
// constructor sets up the memory DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);
m_pDC = pDC;
m_pOldBitmap = NULL;
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);//设置位图起始点坐标为 (m_rect.left, m_rect.top)
FillSolidRect(m_rect, CR_DEFAULT_BK);
}
// 析构函数用于向窗口中复制图象
~CMemDC()
{
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
m_bitmap.DeleteObject();
}
// Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CUSTOMGRID_H__85890F9E_7296_11D4_ACD5_00104B12129F__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -