一个画无限条直线的MFC程序
我要画无限条直线,代码如下,我检查过,代码应该是没什么问题的,就是显示不出来,为什么,我是用vs2017写的,求前辈指导Cobject.h
class graph:public CObject
{
public:
int x0, x1, y0, y1;
graph() { x0 = x1 = y0 = y1 = 0; }
virtual void Cair(){}
virtual void Draw(CDC*pDC){}
};
class Line :public graph
{
public:
Line() { x0 = x1 = y0 = y1 = 0; }
virtual ~Line(){}
void Draw(CDC*pDC)
{
pDC->MoveTo(x0, y0);
pDC->MoveTo(x1, y1);
}
};
CCMZTEXT3View.h部分核心代码
#include"Cobject.h"
class CCMZTEXT3View : public CView
{
protected: // 仅从序列化创建
CCMZTEXT3View() noexcept;
DECLARE_DYNCREATE(CCMZTEXT3View)
// 特性
public:
CCMZTEXT3Doc* GetDocument() const;
int DrawWhat;
CTypedPtrArray<CObArray, graph*>m_graph;
graph *g;
bool IsDown;
CCMZTEXT3View.cpp部分核心代码
CCMZTEXT3View::CCMZTEXT3View() noexcept
{
IsDown = false;
DrawWhat = 1;
// TODO: 在此处添加构造代码
}
void CCMZTEXT3View::OnDraw(CDC* pDC)
{
CCMZTEXT3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
int i = m_graph.GetSize(), j;
for (j = 0; j < i; j++)
{
graph*pObject = m_graph[j];
pObject->Draw(pDC);
}
if (IsDown)
{
g->Draw(pDC);
}
void CCMZTEXT3View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
IsDown = true;
if (DrawWhat == 1)
{
g = new Line();
g->x0 = point.x;
g->y0 = point.y;
}
CView::OnLButtonDown(nFlags, point);
}
void CCMZTEXT3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
IsDown = false;
m_graph.Add(g);
CView::OnLButtonUp(nFlags, point);
}
void CCMZTEXT3View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (IsDown)
{
g->x1 = point.x;
g->y1 >= point.y;
Invalidate();
}
CView::OnMouseMove(nFlags, point);
}
void CCMZTEXT3View::OnLine()
{
DrawWhat = 1;
// TODO: 在此添加命令处理程序代码
}
我已经在菜单栏中添加的画直线的ID了,ID是ID_line;