CHTRichEdit rich text edit control instance of HTControl class in VC++

  • 2020-04-02 02:33:04
  • OfStack

The CHTRichEdit control class described in this paper is inherited from CRichEditCtrl. In order to avoid the interface style of CRichEditCtrl and the scrollbar of CRichEditCtr are not coordinated, so the default scrollbar of CRichEditCtrl is removed from CHTRichEdit control and replaced with the scrollbar drawn by itself, so as not to damage the overall appearance. The replacement scroll bar does not need to be the same width as the default, is not affected by the operating system theme, can support arbitrary widths, and when the scroll bar is not needed, it will automatically disappear, so that the software layout is not affected.

The specific implementation code is as follows:


#if !defined(__CHTRichEdit_H__)
#define __CHTRichEdit_H__
#include "CHTScrollButton.h"
#include "CHTVertScrollBar.h"
#include "CHTHorzScrollBar.h"
class AFX_CLASS_EXPORT CHTRichEdit : public CRichEditCtrl
{
 DECLARE_DYNAMIC(CHTRichEdit)
public:
 CHTRichEdit();
 virtual ~CHTRichEdit();
protected:
 DECLARE_MESSAGE_MAP()
public:

void CreateButton(int iWidth, int iHeight, HBITMAP hBitmapUpNormal, HBITMAP hBitmapUpHover, HBITMAP hBitmapUpDown,
 HBITMAP hBitmapDownNormal, HBITMAP hBitmapDownHover, HBITMAP hBitmapDownDown,
 HBITMAP hBitmapLeftNormal, HBITMAP hBitmapLeftHover, HBITMAP hBitmapLeftDown,
 HBITMAP hBitmapRightNormal, HBITMAP hBitmapRightHover, HBITMAP hBitmapRightDown);

void CreateScrollBar(int iWidth, HBITMAP hBmpVBg, HBITMAP hBmpVThumb, HBITMAP hBmpVHoverThumb, HBITMAP hBmpVPressThumb,
 HBITMAP hBmpHBg, HBITMAP hBmpHThumb, HBITMAP hBmpHHoverThumb, HBITMAP hBmpHPressThumb,
 int iBgTopLen = 0, int iBgBottomLen = 0, int iThumbTopLen = 0, int iThumbBottomLen = 0);
 //The following is the overloaded original interface, you can look up MSDN
 virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
 virtual BOOL CreateEx(DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
 void MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE);
 void MoveWindow(LPCRECT lpRect, BOOL bRepaint = TRUE);
 BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags);
private:
 afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
 afx_msg void OnPaint();
 afx_msg void OnEnChange();
 afx_msg void OnNcPaint();
 afx_msg BOOL OnNcActivate(BOOL bActive);
 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
 afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
 afx_msg void OnEnHscroll();
 afx_msg void OnEnVscroll();
 afx_msg void OnCaptureChanged(CWnd *pWnd);
 afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
 afx_msg void OnTimer(UINT_PTR nIDEvent);
 afx_msg LRESULT OnNcHitTest(CPoint point);
 afx_msg void OnEnRequestresize(NMHDR *pNMHDR, LRESULT *pResult);
 afx_msg void OnSize(UINT nType, int cx, int cy);
 void SetScrollState();
 void UpdateScrollBar();
public:
 CHTScrollButton m_HTButtonUp;
 CHTVertScrollBar m_HTVScrollBar;
 CHTScrollButton m_HTButtonDown;
 CHTScrollButton m_HTButtonLeft;
 CHTHorzScrollBar m_HTHScrollBar;
 CHTScrollButton m_HTButtonRight;
private:
 int m_iBtnHeight;
 int m_iBtnWidth;
 BOOL m_bVScrollBarFlag;
 BOOL m_bHScrollBarFlag;
 int m_iWidth;
 int m_iHeight;
 int m_iX;
 int m_iY;
 BOOL m_bScrollFlag;
 BOOL m_bMoveFlag;
 int m_iScrollBarWidth;
 int m_iScrollBarHeight;
 BOOL m_bFlag;
 int m_iCountV;
 int m_iCountH;
};
#endif //!__CHTRichEdit_H__

The code has some comments that I hope will be helpful in this example.


Related articles: