为什么会出现图中的情况

王金磊 无  2013-07-11 03:10:13
// 画图View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "画图.h"

#include "画图Doc.h"
#include "画图View.h"
#include "SettingDlg.h"
#include<vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(IDM_LINE, OnLine)
ON_COMMAND(IDM_RECTANGLE, OnRectangle)
ON_COMMAND(IDM_Circle, OnCircle)
ON_COMMAND(IDM_Random_Line, OnRandomLine)
ON_COMMAND(IDM_POLYGON, OnPolygon)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(IDM_SET_COLOR, OnSetColor)
ON_COMMAND(IDM_SET_LINE_STYLE_WIDTH, OnSetLineStyleWidth)
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
{
// TODO: add construction code here
m_nDrawType=0;
m_ptOrigin=0;
m_nLineStyle=0;
m_nLineWidth=1;
m_dcMetaFile.Create();
no1=0;
no2=0;
no3=0;
no4=0;
no5=0;
k=0;
}

CMyView::~CMyView()
{
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

//DEL void CMyView::OnUpdateLine(CCmdUI* pCmdUI)
//DEL {
//DEL // TODO: Add your command update UI handler code here
//DEL
//DEL }

void CMyView::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}

void CMyView::OnRectangle()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}

void CMyView::OnCircle()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}

void CMyView::OnRandomLine()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}

void CMyView::OnPolygon()
{
// TODO: Add your command handler code here
m_nDrawType=5;
}

void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
CView::OnLButtonUp(nFlags, point);
}

void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPoint point1,point2;
m_ptOrigin=point;
CMyDoc* pDoc = GetDocument();
if(m_nDrawType==4)
{
pDoc->pointduo[k]=point;
k++;
}
if(m_nDrawType==5)
{
pDoc->pointp[k]=point;
k++;
}
if(no1||no2||no3)
{
switch(m_nDrawType)
{
case 1:if(no1==1)no1=0;break;
case 2:if(no2==1)no2=0;break;
case 3:if(no3==1)no3=0;break;
}
}
else if(m_nDrawType!=0)
{
if(m_nDrawType!=3)
{
CPen pen(0,1,m_color);
CPen* pOldPen = dc.SelectObject(&pen);
point1.x=point.x+5;
point1.y=point.y+5;
point2.x=point.x-5;
point2.y=point.y-5;
dc.Ellipse(CRect(point1,point2));
}
switch(m_nDrawType)
{
case 1:no1=1;
break;
case 2:no2=1;
break;
case 3:no3=1;
break;
case 4:no4=1;
break;
case 5:no5=1;
break;
}
}
CView::OnLButtonDown(nFlags, point);
}

void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint m_ptEnd=point;
CPoint point1,point2,point3,point4;
CMyDoc* pDoc = GetDocument();
CClientDC dc(this);
switch(m_nDrawType)
{
case 1:
pDoc->head=m_ptOrigin;
pDoc->tail=m_ptEnd;
if(no1) Invalidate();
break;
case 2:case 3:
pDoc->m_Rect.left=m_ptOrigin.x;
pDoc->m_Rect.top=m_ptOrigin.y;
pDoc->m_Rect.right=m_ptEnd.x;
pDoc->m_Rect.bottom=m_ptEnd.y;
if(no2 || no3) Invalidate();
case 4:case 5:
pDoc->tail=m_ptEnd;
if(no5 || no4) Invalidate();
break;
}

CView::OnMouseMove(nFlags, point);
}

void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CView::OnRButtonDown(nFlags, point);
}

void CMyView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_nDrawType==4)
{
no4=0;
k=0;
}
if(m_nDrawType==5)
{
no5=0;
k=0;
}
CView::OnRButtonUp(nFlags, point);
}

/*void CMyView::OnSetLineStyleWidth()
{
// TODO: Add your command handler code here

CSettingDlg dlg;
//dlg.DoModal();
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;
if(IDOK==dlg.DoModal())
{
m_nLineWidth=dlg.m_nLineWidth ;
m_nLineStyle=dlg.m_nLineStyle ;
}

}*/

void CMyView::OnSetColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
dlg.m_cc.Flags |=CC_RGBINIT | CC_FULLOPEN;
dlg.m_cc.rgbResult=m_color;
if(IDOK==dlg.DoModal())
{
m_color=dlg.m_cc.rgbResult;
}
}

void CMyView::OnSetLineStyleWidth()
{
// TODO: Add your command handler code here
CSettingDlg dlg;
//dlg.DoModal();
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;
if(IDOK==dlg.DoModal())
{
m_nLineWidth=dlg.m_nLineWidth ;
m_nLineStyle=dlg.m_nLineStyle ;
}
}

...全文
29 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
C++ Builder
创建于2007-08-02

1.3w+

社区成员

C++ Builder相关内容讨论区
申请成为版主
帖子事件
创建了帖子
2013-07-11 03:10
社区公告
暂无公告