rulerricheditctrl.h

来自「管理项目进度工具的原代码」· C头文件 代码 · 共 186 行

H
186
字号
#if !defined(AFX_RULERRICHEDITCTRL_H__4CD13283_82E4_484A_83B4_DBAD5B64F17C__INCLUDED_)
#define AFX_RULERRICHEDITCTRL_H__4CD13283_82E4_484A_83B4_DBAD5B64F17C__INCLUDED_

#include "RulerRichEdit.h"
#include "RRECRuler.h"
#include "RRECToolbar.h"
#include "ids.h"

/////////////////////////////////////////////////////////////////////////////
// Helper structs

#ifdef _UNICODE
struct CharFormat : public CHARFORMAT2W
#else
struct CharFormat : public CHARFORMAT2
#endif
{
	CharFormat()
	{
		memset(this, 0, sizeof (CharFormat));
		cbSize = sizeof(CharFormat);
	};

};

struct ParaFormat : public PARAFORMAT
{
	ParaFormat(DWORD mask)
	{
		memset(this, 0, sizeof (ParaFormat));
		cbSize = sizeof(ParaFormat);
		dwMask = mask;
	}
};

/////////////////////////////////////////////////////////////////////////////
// CRulerRichEditCtrl window

class CRulerRichEditCtrl : public CWnd
{

public:
// Construction/creation/destruction
	CRulerRichEditCtrl();
	virtual ~CRulerRichEditCtrl();
	virtual BOOL Create(DWORD dwStyle, const RECT &rect, CWnd* pParentWnd, UINT nID, BOOL autohscroll = FALSE);

// Attributes
	void	SetMode(int mode);
	int		GetMode() const;

	void ShowToolbar(BOOL show = TRUE);
	void ShowRuler(BOOL show = TRUE);

	BOOL IsToolbarVisible() const;
	BOOL IsRulerVisible() const;

	void SetWordWrap(BOOL bWrap = TRUE);
	BOOL HasWordWrap() const { return m_bWordWrap; }

	CRulerRichEdit& GetRichEditCtrl();

// Implementation
	CString GetRTF();
	int GetRTFLength();
	void	SetRTF(const CString& rtf);
	BOOL	Save(CString& filename);
	BOOL	Load(CString& filename);

	void SetReadOnly(BOOL readOnly);
	BOOL GetReadOnly() const;

protected:
// Formatting
	virtual void DoFont();
	virtual void DoColor();
	virtual void DoBold();
	virtual void DoItalic();
	virtual void DoUnderline();
	virtual void DoLeftAlign();
	virtual void DoCenterAlign();
	virtual void DoRightAlign();
	virtual void DoIndent();
	virtual void DoOutdent();
	virtual void DoBullet();
	virtual void DoStrikethrough();
	virtual void DoSuperscript();
	virtual void DoSubscript();

	void SetCurrentFontName(const CString& font);
	void SetCurrentFontSize(int points);
	void SetCurrentFontColor(COLORREF color, BOOL bForeground);

// Overrides
	//{{AFX_VIRTUAL(CRulerRichEditCtrl)
	protected:
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	//}}AFX_VIRTUAL

protected:
// Message handlers
	//{{AFX_MSG(CRulerRichEditCtrl)
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnButtonFont();
	afx_msg void OnButtonColor();
	afx_msg void OnButtonBold();
	afx_msg void OnButtonStrikethrough();
	afx_msg void OnButtonItalic();
	afx_msg void OnButtonUnderline();
	afx_msg void OnButtonLeftAlign();
	afx_msg void OnButtonCenterAlign();
	afx_msg void OnButtonRightAlign();
	afx_msg void OnButtonIndent();
	afx_msg void OnButtonOutdent();
	afx_msg void OnButtonBullet();
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg LRESULT OnSetText (WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnGetText (WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnGetTextLength (WPARAM wParam, LPARAM lParam);
	afx_msg void OnEnable(BOOL bEnable);
	//}}AFX_MSG
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg LRESULT OnSetFont(WPARAM wp, LPARAM lp);
	afx_msg void OnEnHScroll();
	afx_msg void OnEnSelChange(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg LRESULT OnUpdateToolbar(WPARAM wParam, LPARAM lParam);
	afx_msg void OnButtonTextColor();
	afx_msg void OnButtonBackColor();

	LRESULT OnTrackRuler(WPARAM mode, LPARAM pt);
	LRESULT OnGetScrollPos(WPARAM, LPARAM);
	LRESULT OnSetCurrentFontName(WPARAM font, LPARAM size);
	LRESULT OnSetCurrentFontSize(WPARAM font, LPARAM size);
	LRESULT OnSetCurrentFontColor(WPARAM font, LPARAM size);

	DECLARE_MESSAGE_MAP()

protected:
	// Internal data
	int				m_rulerPosition;	// The x-position of the ruler line when dragging a tab
	CPen			m_pen;				// The pen to use for drawing the XORed ruler line

	CDWordArray		m_tabs;				// An array containing the tab-positions in device pixels
	int				m_margin;			// The margin to use for the ruler and buttons

	int				m_physicalInch;		// The number of pixels for an inch on screen
	int				m_movingtab;		// The tab-position being moved, or -1 if none
	int				m_offset;			// Internal offset of the tab-marker being moved.
	CharFormat		m_cfDefault;

	BOOL			m_showToolbar;
	BOOL			m_showRuler;
	BOOL			m_readOnly;
	BOOL			m_bWordWrap;
	
	// Sub-controls
	CRulerRichEdit	m_rtf;
	CRRECToolBar	m_toolbar;
	CRRECRuler		m_ruler;

	// Handle to the RTF 2.0 dll
//	HINSTANCE		m_richEditModule;

	// Private helpers
	void	SetTabStops(LPLONG tabs, int size);
	void	UpdateTabStops();

	BOOL	CreateToolbar();
	BOOL	CreateRuler();
	BOOL	CreateRTFControl(BOOL autohscroll);
	void	CreateMargins();

	void	UpdateToolbarButtons();
	void	UpdateEditRect();

	void	SetEffect(int mask, int effect);
	void	SetAlignment(int alignment);

	void	LayoutControls(int width, int height);

};

#endif // !defined(AFX_RULERRICHEDITCTRL_H__4CD13283_82E4_484A_83B4_DBAD5B64F17C__INCLUDED_)

⌨️ 快捷键说明

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