ex81View.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:4k
源码类别:
书籍源码
开发平台:
Visual C++
- // ex81View.cpp : implementation of the CEx81View class
- //
- #include "stdafx.h"
- #include "ex81.h"
- #include "ex81Doc.h"
- #include "ex81View.h"
- #include "GraphicDlg.h"
- #include "EditDlg.h"
- #include "ListDlg.h"
- #include "ComboDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View
- IMPLEMENT_DYNCREATE(CEx81View, CView)
- BEGIN_MESSAGE_MAP(CEx81View, CView)
- //{{AFX_MSG_MAP(CEx81View)
- ON_COMMAND(ID_Graphic, OnGraphic)
- ON_COMMAND(ID_EDITDLG, OnEditdlg)
- ON_COMMAND(IDC_LISTDLG, OnListdlg)
- ON_COMMAND(IDC_COMBODLG, OnCombodlg)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View construction/destruction
- CEx81View::CEx81View()
- {
- r=0;
- g=0;
- b=0;
- color="红色";
- }
- CEx81View::~CEx81View()
- {
- }
- BOOL CEx81View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View drawing
- void CEx81View::OnDraw(CDC* pDC)
- {
- CEx81Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CBrush brush(RGB(r,g,b));
- pDC->SelectObject(&brush);
- pDC->Ellipse(100,100,200,200);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View printing
- BOOL CEx81View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CEx81View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CEx81View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View diagnostics
- #ifdef _DEBUG
- void CEx81View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CEx81View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CEx81Doc* CEx81View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx81Doc)));
- return (CEx81Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEx81View message handlers
- void CEx81View::OnGraphic()
- {
- CGraphicDlg dlg;
- CDC *pDC=GetDC();
- r=0;
- g=0;
- b=0;
- if(dlg.DoModal()==IDOK)
- {
- if(dlg.m_bChkRed)
- r=255;
- if(dlg.m_bChkGreen)
- g=255;
- if(dlg.m_bChkBlue)
- b=255;
- CBrush brush(RGB(r,g,b));
- pDC->SelectObject(&brush);
- Invalidate();
- UpdateWindow();
- if(!dlg.m_Graphic) //判断选择的单选按钮
- pDC->Ellipse(100,100,200,200);
- else
- pDC->Rectangle(100,100,200,200);
- }
- }
- void CEx81View::OnEditdlg()
- {
- CEditDlg dlg;
- dlg.m_nEditRed=r;
- dlg.m_nEditGreen=g;
- dlg.m_nEditBlue=b;
- if(dlg.DoModal()==IDOK)
- {
- r=dlg.m_nEditRed;
- g=dlg.m_nEditGreen;
- b=dlg.m_nEditBlue;
- Invalidate();//通过该函数调用OnDraw函数
- }
- }
- void CEx81View::OnListdlg()
- {
- CListDlg dlg;
- dlg.m_strColor=color;//color为一表示颜色的字符串,初始化为color="红色"
- if(dlg.DoModal()==IDOK)
- {
- color=dlg.m_strColor;
- if(color=="红色")
- {
- r=255;
- g=b=0;
- }
- if(color=="绿色")
- {
- r=b=0;
- g=255;
- }
- if(color=="蓝色")
- {
- r=g=0;
- b=255;
- }
- Invalidate();
- }
- }
- void CEx81View::OnCombodlg()
- {
- CComboDlg dlg;
- dlg.m_strColor=color;
- if(dlg.DoModal()==IDOK)
- {
- color=dlg.m_strColor;
- if(color=="红色")
- {
- r=255;
- g=b=0;
- }
- if(color=="绿色")
- {
- r=b=0;
- g=255;
- }
- if(color=="蓝色")
- {
- r=g=0;
- b=255;
- }
- Invalidate();
- }
- }