ex71View.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:3k
源码类别:
书籍源码
开发平台:
Visual C++
- // ex71View.cpp : implementation of the CEx71View class
- //
- #include "stdafx.h"
- #include "ex71.h"
- #include "ex71Doc.h"
- #include "ex71View.h"
- #include "PenDlg.h"
- //#include "NPenDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View
- IMPLEMENT_DYNCREATE(CEx71View, CView)
- BEGIN_MESSAGE_MAP(CEx71View, CView)
- //{{AFX_MSG_MAP(CEx71View)
- ON_COMMAND(ID_TESTDLG, OnTestdlg)
- ON_COMMAND(ID_Modal, OnModal)
- ON_COMMAND(ID_NoModal, OnNoModal)
- ON_MESSAGE(WM_APPLY,Apply)
- //}}AFX_MSG_MAP
- // 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)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View construction/destruction
- CEx71View::CEx71View()
- {
- m_nWidth=1; //将当前画笔宽度设置为1
- }
- CEx71View::~CEx71View()
- {
- }
- BOOL CEx71View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View drawing
- void CEx71View::OnDraw(CDC* pDC)
- {
- CEx71Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CPen pen;
- pen.CreatePen(PS_SOLID,m_nWidth,RGB(255,0,0)); //创建画笔
- pDC->SelectObject(&pen);
- pDC->Ellipse(100,100,300,300); //画圆
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View printing
- BOOL CEx71View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CEx71View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CEx71View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View diagnostics
- #ifdef _DEBUG
- void CEx71View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CEx71View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CEx71Doc* CEx71View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx71Doc)));
- return (CEx71Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEx71View message handlers
- void CEx71View::OnTestdlg()
- {
- CPenDlg dlg;
- dlg.DoModal();
- }
- void CEx71View::OnModal()
- {
- CPenDlg dlg;
- dlg.m_nWidthEdit=m_nWidth;// 将视图中的m_nWidth赋给对话框中的m_nWidthEdit
- if(dlg.DoModal()==IDOK)//调用DoModal()显示对话框,如果单击OK关闭对话框
- {
- m_nWidth=dlg.m_nWidthEdit; //对话框中的m_nWidthEdit赋给将视图中的m_nWidth
- Invalidate();//调用OnDraw()函数用新画笔重绘图形
- }
- }
- void CEx71View::OnNoModal()
- {
- NpenDlg=new CNPenDlg(this);
- NpenDlg->m_nWidthEdit=m_nWidth;
- NpenDlg->Create(CNPenDlg::IDD);
- NpenDlg->ShowWindow(SW_SHOW);
- }
- void CEx71View::Apply(WPARAM wParam, LPARAM lParam)
- {
- m_nWidth=NpenDlg->m_nWidthEdit; //将对话框中m_nWidthEdit的值传给视图的m_nWidth;
- Invalidate(); //重绘图形
- }