MFC的一个简单功能,怎么都不行,为什么呢?
功能是实现,点击左键则显示“鼠标左键被按下!”view.h//
// ExMouseView.h : CExMouseView 类的接口
//
#pragma once
class CExMouseView : public CView
{
protected: // 仅从序列化创建
CExMouseView();
DECLARE_DYNCREATE(CExMouseView)
// 属性
public:
CExMouseDoc* GetDocument() const;
// 操作
public:
// 重写
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// 实现
public:
virtual ~CExMouseView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// 生成的消息映射函数
protected:
DECLARE_MESSAGE_MAP()
public:
Point m_ptMouse;
public:
CString m_szDes;
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};
#ifndef _DEBUG // ExMouseView.cpp 中的调试版本
inline CExMouseDoc* CExMouseView::GetDocument() const
{ return reinterpret_cast<CExMouseDoc*>(m_pDocument); }
#endif
view.cpp//
// ExMouseView.cpp : CExMouseView 类的实现
//
#include "stdafx.h"
#include "ExMouse.h"
#include "ExMouseDoc.h"
#include "ExMouseView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CExMouseView
IMPLEMENT_DYNCREATE(CExMouseView, CView)
BEGIN_MESSAGE_MAP(CExMouseView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// CExMouseView 构造/析构
CExMouseView::CExMouseView()
: m_ptMouse(0)
, m_szDes(_T(""))
{
// TODO: 在此处添加构造代码
}
CExMouseView::~CExMouseView()
{
}
BOOL CExMouseView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CExMouseView 绘制
void CExMouseView::OnDraw(CDC* /*pDC*/)
{
CExMouseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CDC* pDC = GetDC();
pDC->TextOutW(m_ptMouse.x, m_ptMouse.y, m_szDes);
ReleaseDC(pDC);
}
// CExMouseView 打印
BOOL CExMouseView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CExMouseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CExMouseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清除过程
}
// CExMouseView 诊断
#ifdef _DEBUG
void CExMouseView::AssertValid() const
{
CView::AssertValid();
}
void CExMouseView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExMouseDoc* CExMouseView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExMouseDoc)));
return (CExMouseDoc*)m_pDocument;
}
#endif //_DEBUG
// CExMouseView 消息处理程序
void CExMouseView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_ptMouse = point;
m_szDes = _T("鼠标左键被按下!");
InvalidateRect(NULL);
CView::OnLButtonDown(nFlags, point);
}
但总报错说:
46: syntax error : missing ';' before identifier 'm_ptMouse'
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>ExMouseView.cpp
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.h(44) : error C2146: syntax error : missing ';' before identifier 'm_ptMouse'
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.cpp(32) : error C2614: 'CExMouseView' : illegal member initialization: 'm_ptMouse' is not a base or member
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.cpp(60) : error C2065: 'm_ptMouse' : undeclared identifier
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.cpp(60) : error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>e:\c++\mfc work\exmouse\exmouse\exmouseview.cpp(60) : error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type
感觉自己对了得 ,添加变量, 事件 ,消息,都按照书上的步骤进行的,编译器也一样,就是报错,好郁闷