//这里是 CMainWindow.h#include<afxwin.h>
#include <afxtempl.h>class CLine : public CObject
{
public:
DECLARE_SERIAL(CLine)public:
CLine();
CLine(CPoint,CPoint);
void Serialize(CArchive&); CPoint m_ptFrom;
CPoint m_ptTo;};//双击错误提示,VC2008指向这行
class CMainWindow : public CFrameWnd
{
public:
DECLARE_MESSAGE_MAP()
public:
CMainWindow(); CPoint m_ptFrom;
CPoint m_ptTo; int nCount; CArray <CLine,CLine&> lines; afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
};//这里是 CMainWindow.cpp#include "CMainWindow.h"
#include<locale.h>
#include<TCHAR.H>BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
CMainWindow::CMainWindow()
{
Create(0,L"");
nCount = 0;
}void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptFrom = point;
m_ptTo = point;
}
void CMainWindow::OnMouseMove(UINT nFlags, CPoint point)
{
if( nFlags & MK_LBUTTON )
{ CClientDC dc(this);

dc.SetROP2(R2_NOT); dc.MoveTo( m_ptFrom );
dc.LineTo( point ); dc.MoveTo( m_ptFrom );
dc.LineTo( m_ptTo ); m_ptTo = point;

}}void CMainWindow::OnLButtonUp(UINT nFlags, CPoint point)
{ nCount++;
lines.Add( CLine(m_ptFrom,m_ptTo) );
}
void CMainWindow::OnPaint()
{}void CMainWindow::OnRButtonDown(UINT nFlags, CPoint point)
{
}//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
CLine::CLine()
{
}CLine::CLine(CPoint p1, CPoint p2):
m_ptFrom(p1), m_ptTo(p2)
{
}void CLine::Serialize(CArchive & ar)
{
CObject::Serialize(ar);
if(ar.IsStoring())
ar << m_ptFrom << m_ptTo;
else
ar >> m_ptFrom >> m_ptTo;
}IMPLEMENT_SERIAL(CLine, CObject, 1)1>------ 已启动生成: 项目: mfc, 配置: Debug Win32 ------
1>正在编译...
1>CMainWindow.cpp
1> WINVER not defined. Defaulting to 0x0600 (Windows Vista)
1>c:\users\administrator\desktop\mfc\mfc\cmainwindow.h(19) : error C2248: “CObject::operator =”: 无法访问 private 成员(在“CObject”类中声明)
1>        d:\vc++ 2008\vc\atlmfc\include\afx.h(552) : 参见“CObject::operator =”的声明
1>        d:\vc++ 2008\vc\atlmfc\include\afx.h(522) : 参见“CObject”的声明
1>        此诊断出现在编译器生成的函数“CLine &CLine::operator =(const CLine &)”中
1>正在生成代码...
1>正在编译...
1>CMyApp.cpp
1> WINVER not defined. Defaulting to 0x0600 (Windows Vista)
1>正在生成代码...
1>生成日志保存在“file://c:\Users\Administrator\Desktop\mfc\mfc\Debug\BuildLog.htm”
1>mfc - 1 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========