Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MFC2View.cpp : implementation of the CMFC2View class
- //
- #include "stdafx.h"
- #include "MFC2.h"
- #include "MFC2Doc.h"
- #include "MFC2View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CMFC2View
- IMPLEMENT_DYNCREATE(CMFC2View, CView)
- BEGIN_MESSAGE_MAP(CMFC2View, 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)
- END_MESSAGE_MAP()
- // CMFC2View construction/destruction
- CMFC2View::CMFC2View()
- {
- // TODO: add construction code here
- }
- CMFC2View::~CMFC2View()
- {
- }
- BOOL CMFC2View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- // CMFC2View drawing
- void CMFC2View::OnDraw(CDC* pDC)
- {
- CMFC2Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if (!pDoc)
- return;
- /*CPen *PenOld,PenNew;
- CBrush *BrushOld,BrushNew;
- PenOld = (CPen *)pDC->SelectStockObject(BLACK_PEN);
- BrushOld = (CBrush *)pDC->SelectStockObject(LTGRAY_BRUSH);
- pDC->Rectangle(100,100,300,300);
- PenNew.CreateStockObject(WHITE_PEN);
- pDC->SelectObject(&PenNew);
- pDC->MoveTo(100,100);
- pDC->LineTo(300,300);
- pDC->MoveTo(100,300);
- pDC->LineTo(300,100);
- pDC->SelectObject(PenOld);
- pDC->SelectObject(BrushOld);*/
- CPen *PenOld,PenNew;
- int PenStyle[]={PS_SOLID,PS_DOT,PS_DASH};
- char *strStyle[]={"实线","点线","虚线"};
- char *strWidth[]={"1","2","3"};
- char *strColor[]={"红","绿","蓝"};
- char *p;
- int x,y,t,width=1;
- COLORREF rgbPenclr[]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255)};
- COLORREF PenColor=RGB(0,0,0);
- pDC->TextOut(60,10,"用不同样式的画笔绘图");
- pDC->TextOut(260,10,"用不同样式的画笔绘图");
- pDC->TextOut(460,10,"用不同样式的画笔绘图");
- for(int i=0;i<3;i++){
- for(int j=0;j<3;j++){
- x=(i<<1)+1;
- if(i==0){
- y=j;
- t=1;
- p=strStyle[j];
- }else if(i==1){
- y=0;
- t=26;
- width=j+1;
- p=strWidth[j];
- }else{
- y=j;
- t=46;
- PenColor=rgbPenclr[j];
- p=strColor[j];
- }
- PenNew.CreatePen(PenStyle[y],width,PenColor);
- PenOld=pDC->SelectObject(&PenNew);
- pDC->TextOut(10*t,35+52*j,p);
- pDC->Rectangle(100*x,40+50*j,100*(x+1),60+50*j);
- pDC->SelectObject(PenOld);
- PenNew.DeleteObject();
- }
- }
- /*pDC->RoundRect(100,30,250,100,30,30);
- pDC->Ellipse(200,100,400,150);*/
- // TODO: add draw code for native data here
- }
- // CMFC2View printing
- BOOL CMFC2View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMFC2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMFC2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- // CMFC2View diagnostics
- #ifdef _DEBUG
- void CMFC2View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMFC2View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMFC2Doc* CMFC2View::GetDocument() const // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFC2Doc)));
- return (CMFC2Doc*)m_pDocument;
- }
- #endif //_DEBUG
- // CMFC2View message handlers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement