⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageeditorview.h

📁 在mfc环境下实现的绘图板程序
💻 H
字号:
/*
 *   Author   :  msz
 *   Mail     :  jinhao7654321@163.com
 */
// ImageEditorView.h : CImageEditorView 类的接口
//

#ifndef __CIMAGEEDITORVIEW__
#define __CIMAGEEDITORVIEW__

#pragma once
#include ".\ADMMScrollview.h"
#include <atlimage.h>
#include <comdef.h>
class Stack;
class CDrawObject;
class CColorPaletteBar;
class CMainFrame;
class CImageEditorDoc;

enum SelectMode
{
	smNone,
	smSelect,
	smMove,
	smSize,
	smSizeCanvas,
	smPenDraw,
	smShapeDraw,
	smAreaDraw,
	smTextDraw,
	smEdit
};

class CImageEditorView : public CADMMScrollView
{

protected: // 仅从序列化创建
	CImageEditorView();
	DECLARE_DYNCREATE(CImageEditorView)

// 属性
public:
	CImageEditorDoc* GetDocument() const;
private:
	float	m_fZoomScale;
	UINT	m_nCurToolIndex; //当前工具的
	CSize	m_sizeCanvas;    //图像的大小 logic Unit
	CImage	m_imgCurent;
	CPoint  m_ptPrev, m_ptStart;       // the last mouse pt in the stroke in progress
	Stack  *m_pHistoryStack;
	CDrawObject* m_pCurObj;
	CEdit*	m_pEditBox;
	CFont   m_fontEditBox;
	SelectMode m_curMode;
	BOOL	m_bCurrentObjectIsActive;
	int		m_nDragHandle;
	int		m_nCanvasHandle;
	UINT	m_emBrushStyle, m_emLineWidth, m_emShapeStyle;

	void UpdateViewSize();
	void DrawBackGround(CDC *pDC);
	void DoDraw(CDC *pDC, BOOL bToScreen=FALSE);
	BOOL CreatDefaultImage(void);
	HBITMAP CanvasToBmp(void);
	void InitHistory(HBITMAP hBmp);
	void RecordHistory();
	BOOL IsPointInCanvas(const CPoint& point);
	void InvalidateObj(CDrawObject* pObj);
	void ResetCurrentObj(CDrawObject* pNewObj);
	void MyDrawFocusRect(const CPoint& pt1, const CPoint& pt2);
	void ShowEditBox(const CRect& rect, const CString& strText=_T(""););
	void HidenEditBox(void);
	CColorPaletteBar* GetColorBar();
	void SetInitState(void);

	//画布边缘
	int HitCanvasTest(CPoint point);
	void DrawCanvasTracker(CDC* pDC);
	CRect GetCanvasHandleRect(int nHandleID);
	CPoint GetCanvasHandle(int nHandle);
// 操作
	void DocToClient(CPoint& point);
	void DocToClient(CRect& rect);
	void DocToClient(CSize& size);
	void ClientToDoc(CPoint& point);
	void ClientToDoc(CRect& rect);
	void ClientToDoc(CSize& size);

	static BOOL SaveImageToBase64String(CString& strResult,const CImage* pImg);
	static BOOL LoadImageFromBase64String(CString& strSrc,CImage* pImg);
public:
	void SetZoomScale(float fValue);
	BOOL LoadFromString(CString& strSrc);
	CString SaveToString(void);

// 重写
public:
	virtual void OnDraw(CDC* pDC);  // 重写以绘制该视图
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual void OnInitialUpdate(); // 构造后第一次调用
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// 实现
public:
	virtual ~CImageEditorView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// 生成的消息映射函数
protected:
	DECLARE_MESSAGE_MAP()
	afx_msg void OnSelectEditTool(UINT id = 0);
	afx_msg void OnUpdateSelectEditTool(CCmdUI* pCmdUI);
public:
	virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnFileOpen();
	afx_msg void OnFileSave();
	afx_msg void OnEditCut();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnEditUndo();
	afx_msg void OnUpdateEditUndo(CCmdUI *pCmdUI);
	afx_msg void OnEditRedo();
	afx_msg void OnUpdateEditRedo(CCmdUI *pCmdUI);
	afx_msg void OnEditCopy();
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnEditPaste();
	void OnDelete();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg LRESULT OnHotKey(WPARAM wParam,LPARAM lParam);
	afx_msg void OnToolStyleChange(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
};

#ifndef _DEBUG  // ImageEditorView.cpp 中的调试版本
inline CImageEditorDoc* CImageEditorView::GetDocument() const
   { return reinterpret_cast<CImageEditorDoc*>(m_pDocument); }
#endif

#endif

⌨️ 快捷键说明

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