Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. // MFC2View.cpp : implementation of the CMFC2View class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MFC2.h"
  6.  
  7. #include "MFC2Doc.h"
  8. #include "MFC2View.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13.  
  14.  
  15. // CMFC2View
  16.  
  17. IMPLEMENT_DYNCREATE(CMFC2View, CView)
  18.  
  19. BEGIN_MESSAGE_MAP(CMFC2View, CView)
  20.     // Standard printing commands
  21.     ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
  22.     ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
  23.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25.  
  26. // CMFC2View construction/destruction
  27.  
  28. CMFC2View::CMFC2View()
  29. {
  30.     // TODO: add construction code here
  31.  
  32. }
  33.  
  34. CMFC2View::~CMFC2View()
  35. {
  36. }
  37.  
  38. BOOL CMFC2View::PreCreateWindow(CREATESTRUCT& cs)
  39. {
  40.     // TODO: Modify the Window class or styles here by modifying
  41.     //  the CREATESTRUCT cs
  42.  
  43.     return CView::PreCreateWindow(cs);
  44. }
  45.  
  46. // CMFC2View drawing
  47.  
  48. void CMFC2View::OnDraw(CDC* pDC)
  49. {
  50.     CMFC2Doc* pDoc = GetDocument();
  51.     ASSERT_VALID(pDoc);
  52.     if (!pDoc)
  53.         return;
  54.     /*CPen *PenOld,PenNew;
  55.     CBrush *BrushOld,BrushNew;
  56.     PenOld = (CPen *)pDC->SelectStockObject(BLACK_PEN);
  57.     BrushOld = (CBrush *)pDC->SelectStockObject(LTGRAY_BRUSH);
  58.     pDC->Rectangle(100,100,300,300);
  59.     PenNew.CreateStockObject(WHITE_PEN);
  60.     pDC->SelectObject(&PenNew);
  61.     pDC->MoveTo(100,100);
  62.     pDC->LineTo(300,300);
  63.     pDC->MoveTo(100,300);
  64.     pDC->LineTo(300,100);
  65.     pDC->SelectObject(PenOld);
  66.     pDC->SelectObject(BrushOld);*/
  67.     CPen *PenOld,PenNew;
  68.     int PenStyle[]={PS_SOLID,PS_DOT,PS_DASH};
  69.     char *strStyle[]={"实线","点线","虚线"};
  70.     char *strWidth[]={"1","2","3"};
  71.     char *strColor[]={"红","绿","蓝"};
  72.     char *p;
  73.     int x,y,t,width=1;
  74.     COLORREF rgbPenclr[]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255)};
  75.     COLORREF PenColor=RGB(0,0,0);
  76.     pDC->TextOut(60,10,"用不同样式的画笔绘图");
  77.     pDC->TextOut(260,10,"用不同样式的画笔绘图");
  78.     pDC->TextOut(460,10,"用不同样式的画笔绘图");
  79.     for(int i=0;i<3;i++){
  80.         for(int j=0;j<3;j++){
  81.             x=(i<<1)+1;
  82.             if(i==0){
  83.                 y=j;
  84.                 t=1;
  85.                 p=strStyle[j];
  86.             }else if(i==1){
  87.                 y=0;
  88.                 t=26;
  89.                 width=j+1;
  90.                 p=strWidth[j];
  91.             }else{
  92.                 y=j;
  93.                 t=46;
  94.                 PenColor=rgbPenclr[j];
  95.                 p=strColor[j];
  96.             }
  97.             PenNew.CreatePen(PenStyle[y],width,PenColor);
  98.             PenOld=pDC->SelectObject(&PenNew);
  99.             pDC->TextOut(10*t,35+52*j,p);
  100.             pDC->Rectangle(100*x,40+50*j,100*(x+1),60+50*j);
  101.             pDC->SelectObject(PenOld);
  102.             PenNew.DeleteObject();
  103.         }
  104.     }
  105.     /*pDC->RoundRect(100,30,250,100,30,30);
  106.     pDC->Ellipse(200,100,400,150);*/
  107.     // TODO: add draw code for native data here
  108. }
  109.  
  110.  
  111. // CMFC2View printing
  112.  
  113. BOOL CMFC2View::OnPreparePrinting(CPrintInfo* pInfo)
  114. {
  115.     // default preparation
  116.     return DoPreparePrinting(pInfo);
  117. }
  118.  
  119. void CMFC2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  120. {
  121.     // TODO: add extra initialization before printing
  122. }
  123.  
  124. void CMFC2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  125. {
  126.     // TODO: add cleanup after printing
  127. }
  128.  
  129.  
  130. // CMFC2View diagnostics
  131.  
  132. #ifdef _DEBUG
  133. void CMFC2View::AssertValid() const
  134. {
  135.     CView::AssertValid();
  136. }
  137.  
  138. void CMFC2View::Dump(CDumpContext& dc) const
  139. {
  140.     CView::Dump(dc);
  141. }
  142.  
  143. CMFC2Doc* CMFC2View::GetDocument() const // non-debug version is inline
  144. {
  145.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFC2Doc)));
  146.     return (CMFC2Doc*)m_pDocument;
  147. }
  148. #endif //_DEBUG
  149.  
  150.  
  151. // CMFC2View message handlers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement