帮我看看(100分)

  • 主题发起人 主题发起人 mjf_jigh
  • 开始时间 开始时间
M

mjf_jigh

Unregistered / Unconfirmed
GUEST, unregistred user!
我建立了win32 Application
程序如下:请帮我看下谢谢。
当我运行文件菜单下的菜单项时有错误
#include<afxwin.h>
#include"resource.h"
#include<afxtempl.h>
#include<afxext.h>
class GraphicObject:public CObject
{
public:
int shapenum;
BOOL fill;
COLORREF FillColor,LineColor;
int width;
CPoint StartPnt,EndPnt;
GraphicObject()
{}
GraphicObject(int shapenum,BOOL fill,COLORREF FillColor,COLORREF LineColor,int width,CPoint StartPnt,CPoint EndPnt)
:shapenum(shapenum),fill(fill),FillColor(FillColor),LineColor(LineColor),width(width),StartPnt(StartPnt),EndPnt(EndPnt)
{}
GraphicObject(GraphicObject &amp;g)
:shapenum(g.shapenum),fill(g.fill),FillColor(g.FillColor),
LineColor(g.LineColor),width(g.width),StartPnt(g.StartPnt),EndPnt(g.EndPnt)
{
}
GraphicObject &amp;
operator= (GraphicObject &amp;g)
{
shapenum=g.shapenum;
fill=g.fill;
FillColor=g.FillColor;
LineColor=g.LineColor;
width=g.width;
StartPnt=g.StartPnt;
EndPnt=g.EndPnt;
return *this;
}
void Serialize(CArchive &amp;ar)
{
CObject::Serialize(ar);
if(ar.IsStoring())
{
ar<<shapenum<<fill<<FillColor<<LineColor<<width<<StartPnt<<EndPnt;
}
else
{
ar>>shapenum>>fill>>FillColor>>LineColor>>width>>StartPnt>>EndPnt;
}
}
DECLARE_SERIAL(GraphicObject)
};
IMPLEMENT_SERIAL(GraphicObject,CObject,1)
class Shape
{
protected:
CPoint StartPnt,EndPnt;
int shapenum;
friend class MyView;
public:
Shape(CPoint StartPnt,CPoint EndPnt,int shapenum)
:shapenum(shapenum),StartPnt(StartPnt),EndPnt(EndPnt)
{
}
Shape()
{
}
Shape(Shape &amp;s):
shapenum(s.shapenum),StartPnt(s.StartPnt),EndPnt(s.EndPnt)
{
}
Shape &amp;
operator= (Shape &amp;s)
{
StartPnt=s.StartPnt;
EndPnt=s.EndPnt;
return *this;
}
virtual void draw(CDC &amp;
aDC,COLORREF color,COLORREF fcolor,int width,BOOL Filled=false)=0;
int GetShapeNum()
{
return shapenum;
}
void SetPoint(CPoint SPnt,CPoint EPnt)
{
StartPnt=SPnt;
EndPnt=EPnt;
}
};
class Line:public Shape
{
public :
friend class MyView;
Line()
{
shapenum=0;
}
Line(CPoint StartPnt,CPoint EndPnt):
Shape(StartPnt,EndPnt,0)
{
}
Line(Line &amp;l):
Shape(l.StartPnt,l.EndPnt,0)
{
}
Line &amp;
operator= (Line &amp;
l)
{
StartPnt=l.StartPnt;
EndPnt=l.EndPnt;
return *this;
}
void draw(CDC &amp;dc,COLORREF color,COLORREF fcolor,int width,BOOL Filled=false)
{
CPen pen(PS_SOLID,width,color);
CPen *oldpen=dc.SelectObject(&amp;pen);
dc.MoveTo(StartPnt);
dc.LineTo(EndPnt);
dc.SelectObject(oldpen);
}
};
class ellipse:public Shape
{
public :
ellipse()
{
shapenum=1;
}
ellipse(CPoint StartPnt,CPoint EndPnt):
Shape(StartPnt,EndPnt,1)
{
}
ellipse(ellipse &amp;
e):
Shape(e.StartPnt,e.EndPnt,1)
{
}
ellipse &amp;
operator= (ellipse &amp;
e)
{
StartPnt=e.StartPnt;
EndPnt=e.EndPnt;
return * this;
}
void draw(CDC &amp;dc,COLORREF color,COLORREF fcolor,int width,BOOL Filled=false)
{
CRect rect(StartPnt,EndPnt);
CPen pen(PS_SOLID,width,color);
CPen *oldpen=dc.SelectObject(&amp;pen);
dc.SelectStockObject(NULL_BRUSH);
dc.Ellipse(rect);
dc.SelectObject(oldpen);
}
};
class rectangle:public Shape
{
public:
rectangle()
{
shapenum=2;
}
rectangle(CPoint StartPnt,CPoint EndPnt):
Shape(StartPnt,EndPnt,2)
{
}
rectangle(rectangle &amp;r):
Shape(r.StartPnt,r.EndPnt,2)
{
}
rectangle &amp;
operator= (rectangle &amp;r)
{
StartPnt=r.StartPnt;
EndPnt=r.EndPnt;
return *this;
}
void draw(CDC &amp;dc,COLORREF color,COLORREF fcolor,int width,BOOL Filled=false)
{
CRect rect(StartPnt,EndPnt);
CPen pen(PS_SOLID,width,color);
CPen *oldpen=dc.SelectObject(&amp;pen);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(rect);
dc.SelectObject(oldpen);
}
};
class MyDocument:public CDocument
{
private:
CArray<GraphicObject,GraphicObject> gArray;
public:
void AddObject(GraphicObject &amp;g)
{
SetModifiedFlag(true);
gArray.Add(g);
}
GraphicObject &amp;
GetObject(int i)
{
return gArray;
}
int GetSize()
{
return gArray.GetSize();
}
void Serialize(CArchive &amp;ar)
{
CObject::Serialize(ar);
gArray.Serialize(ar);
}
void DeleteContents()
{
gArray.RemoveAll();
CDocument::DeleteContents();
}
DECLARE_DYNCREATE(MyDocument)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyDocument,CDocument)
begin
_MESSAGE_MAP(MyDocument,CDocument)
END_MESSAGE_MAP()
class MyFrame:public CFrameWnd
{
protected:
CMenu *menu;
public:
CToolBar toolbar;
CStatusBar statusbar;
MyFrame()
{}
~MyFrame()
{}
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CFrameWnd::OnCreate(lpCreateStruct))
return 1;
toolbar.Create(this);
toolbar.LoadToolBar(IDR_MyFrame);
toolbar.EnableDocking(CBRS_ALIGN_ANY);
toolbar.SetBarStyle(toolbar.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&amp;toolbar);
static UINT indicators[]=
{
ID_SEPARATOR,
IDS_Color,
IDS_Shape
};
statusbar.Create(this);
statusbar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));
return 0;
}
DECLARE_DYNCREATE(MyFrame)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyFrame,CFrameWnd)
begin
_MESSAGE_MAP(MyFrame,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
class MyView:public CView
{
private:
COLORREF lcolor,fcolor;
Shape *aShape;
Shape *rdShape;
int width;
public:
MyView()
{
lcolor=RGB(255,0,0);
aShape=new Line;
fcolor=RGB(0,0,0);
width=2;
}
~MyView()
{
}
afx_msg void OnEllipse()
{
aShape=new ellipse;
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(2,"Ellipse");
}
afx_msg void OnRect()
{
aShape=new rectangle;
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(2,"Rectangle");
}
afx_msg void OnLine()
{
aShape=new Line;
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(2,"Line");
}
afx_msg void OnDraw(CDC *aDC)
{
MyDocument *doc=(MyDocument *)GetDocument();
int num=doc->GetSize();
CView::OnDraw(aDC);
int i;
for(i=0;i<num;++i)
{
GraphicObject *object=&amp;(doc->GetObject(i));
switch(object->shapenum)
{
case 0:
rdShape=new Line;
break;
case 1:
rdShape=new ellipse;
break;
case 2:
rdShape=new rectangle;
break;
}
rdShape->SetPoint(object->StartPnt,object->EndPnt);
rdShape->draw((*aDC),object->LineColor,object->FillColor,object->width);
delete rdShape;
}
}
afx_msg void OnLButtonDown(UINT nFlags,CPoint point)
{
SetCapture();
if(this==GetCapture())
aShape->StartPnt=aShape->EndPnt=point;
}
afx_msg void OnMouseMove(UINT nFlags,CPoint point)
{
if(this==GetCapture())
{
CClientDC aDC(this);
aDC.SetROP2(R2_NOT);
aShape->draw(aDC,lcolor,fcolor,width);
aShape->EndPnt=point;
aShape->draw(aDC,lcolor,fcolor,width);
}
}
afx_msg void OnLButtonUp(UINT nFlags,CPoint point)
{
if(this==GetCapture())
{
CClientDC aDC(this);
aShape->EndPnt=point;
aShape->draw(aDC,lcolor,fcolor,width);
GraphicObject object(aShape->GetShapeNum(),true,fcolor,lcolor,width,aShape->StartPnt,aShape->EndPnt);
MyDocument *doc=(MyDocument *)GetDocument();
doc->AddObject(object);
ReleaseCapture();
}
}
afx_msg void OnRed()
{
lcolor=RGB(255,0,0);
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(1,"Red");
}
afx_msg void OnBlue()
{
lcolor=RGB(0,255,0);
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(1,"Blue");
}
afx_msg void OnGreen()
{
lcolor=RGB(0,255,0);
((MyFrame *)GetParentFrame())->statusbar.SetPaneText(1,"Green");
}
afx_msg void OnUpdateEllipse(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(aShape->shapenum==1);
}
afx_msg void OnUpdateRect(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(aShape->shapenum==2);
}
afx_msg void OnUpdateLine(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(aShape->shapenum==0);
}
afx_msg void OnUpdateRed(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(lcolor==RGB(255,0,0));
}
afx_msg void OnUpdateGreen(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(lcolor==RGB(0,255,0));
}
afx_msg void OnUpdateBlue(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(lcolor==RGB(0,0,255));
}
DECLARE_DYNCREATE(MyView)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyView,CView)
begin
_MESSAGE_MAP(MyView,CView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_COMMAND(IDM_Red,OnRed)
ON_COMMAND(IDM_Green,OnGreen)
ON_COMMAND(IDM_Blue,OnBlue)
ON_COMMAND(IDM_Rect,OnRect)
ON_COMMAND(IDM_Line,OnLine)
ON_COMMAND(IDM_Ellipse,OnEllipse)
ON_UPDATE_COMMAND_UI(IDM_Red,OnUpdateRed)
ON_UPDATE_COMMAND_UI(IDM_Green,OnUpdateGreen)
ON_UPDATE_COMMAND_UI(IDM_Blue,OnUpdateBlue)
ON_UPDATE_COMMAND_UI(IDM_Line,OnUpdateLine)
ON_UPDATE_COMMAND_UI(IDM_Rect,OnUpdateRect)
ON_UPDATE_COMMAND_UI(IDM_Ellipse,OnUpdateEllipse)
END_MESSAGE_MAP()
class MyApp:public CWinApp
{
public:
BOOL InitInstance()
{
CDocument *doc;
CSingleDocTemplate *aDocTemplate;
aDocTemplate=new CSingleDocTemplate(
IDR_MyFrame,
RUNTIME_CLASS(MyDocument),
RUNTIME_CLASS(MyFrame),
RUNTIME_CLASS(MyView));
AddDocTemplate(aDocTemplate);
doc=aDocTemplate->CreateNewDocument();
CFrameWnd *frame=aDocTemplate->CreateNewFrame(doc,NULL);
m_pMainWnd=frame;
aDocTemplate->InitialUpdateFrame(frame,doc);
frame->ShowWindow(SW_SHOW);
return true;
}
DECLARE_MESSAGE_MAP()
}a_app;
begin
_MESSAGE_MAP(MyApp,CWinApp)
ON_COMMAND(ID_FILE_NEW,CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN,CWinApp::OnFileOpen)
END_MESSAGE_MAP()

资源文件如下:
菜单分别对应如下:

对应的ID分别为:ID_FILE_NEW
ID_FILE_OPEN
………
IDM_Red
………
IDM_Rect
………….
 
代码太长了,怎么看啊;
 
后退
顶部