MFC 涂鸦板
2012-02-13 18:15
63 查看
// mfclab6View.h : interface of the Cmfclab6View class // #pragma once class Cmfclab6View : public CView { protected: // create from serialization only Cmfclab6View(); DECLARE_DYNCREATE(Cmfclab6View) // Attributes public: Cmfclab6Doc* GetDocument() const; CPoint prevPoint; CPen* pen; bool isDrawing; // Operations public: // Overrides public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); // Implementation public: virtual ~Cmfclab6View(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: afx_msg void OnLButtonDown(UINT flags,CPoint p); afx_msg void OnLButtonUp(UINT flags,CPoint p); afx_msg void OnMouseMove(UINT flags,CPoint p); // Generated message map functions protected: DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in mfclab6View.cpp inline Cmfclab6Doc* Cmfclab6View::GetDocument() const { return reinterpret_cast<Cmfclab6Doc*>(m_pDocument); } #endif // mfclab6View.cpp : implementation of the Cmfclab6View class // #include "stdafx.h" #include "mfclab6.h" #include "mfclab6Doc.h" #include "mfclab6View.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // Cmfclab6View IMPLEMENT_DYNCREATE(Cmfclab6View, CView) BEGIN_MESSAGE_MAP(Cmfclab6View, CView) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview) // ON_WM_LBUTTONDOWN(UINT flags,CPoint p) ON_WM_MOUSEMOVE(UINT flags,CPoint p) ON_WM_LBUTTONUP(UINT flags,CPoint p) END_MESSAGE_MAP() // Cmfclab6View construction/destruction Cmfclab6View::Cmfclab6View() { // TODO: add construction code here this->isDrawing = false; this->pen = new CPen(PS_SOLID,1,1); } Cmfclab6View::~Cmfclab6View() { } BOOL Cmfclab6View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // Cmfclab6View drawing void Cmfclab6View::OnDraw(CDC* pDC) { // TODO: add draw code for native data here } // Cmfclab6View printing BOOL Cmfclab6View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void Cmfclab6View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void Cmfclab6View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ////////////////////// void Cmfclab6View::OnLButtonDown(UINT F,CPoint p){ this->prevPoint = p; SetCapture(); this->isDrawing = true; } void Cmfclab6View::OnLButtonUp(UINT F,CPoint p){ if(GetCapture()!=this){ return; } CClientDC dc(this); CPen* poldPen = dc.SelectObject(this->pen); dc.MoveTo(this->prevPoint.x,this->prevPoint.y); dc.LineTo(p.x,p.y); this->prevPoint = p; this->isDrawing = false; ReleaseCapture(); } void Cmfclab6View::OnMouseMove(UINT F,CPoint p){ if(this->isDrawing){ CClientDC dc(this); CPen* poldPen = dc.SelectObject(this->pen); dc.MoveTo(this->prevPoint.x,this->prevPoint.y); dc.LineTo(p.x,p.y); this->prevPoint = p; } } /////////////////// // Cmfclab6View diagnostics #ifdef _DEBUG void Cmfclab6View::AssertValid() const { CView::AssertValid(); } void Cmfclab6View::Dump(CDumpContext& dc) const { CView::Dump(dc); } Cmfclab6Doc* Cmfclab6View::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cmfclab6Doc))); return (Cmfclab6Doc*)m_pDocument; } #endif //_DEBUG // Cmfclab6View message handlers
相关文章推荐
- asp中command的在单条记录时,有些字段显示为空的问题
- Delphi Command模式
- php设计模式 Command(命令模式)
- IE8引发 VS2005/2008 MFC向导出错的解决方案
- MFC控件 void DrawItem(LPDRAWITEMSTRUCT) { ASSERT(FALSE); }
- ADO.NET与抽水的故事 系列三——抽水机—Command
- command line option syntax error,type command/?
- MFC中CEdit多行情况下,调用GetLine()时,发现老是后面跟有乱码
- LUA整合进MFC代码
- MFC中UpdateData( bool b)函数的用法
- MFC的exe启动时提示应用程序配置不正确,应用程序未能启动错误
- 在MFC程序中显示JPG/GIF图像
- VS2005的C++/MFC应用程序部署问题
- VC++动态链接库编程之MFC扩展 DLL
- MFC 自定义消息
- MFC VC 中 TreeView 全面解析
- CString 操作指南
- 关于逻辑坐标和设备坐标的转换
- VC制作初始画面
- CMemoryState(MFC内存检测类)