| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1093 人关注过本帖
标题:MFC的一个简单功能,怎么都不行,为什么呢?
只看楼主 加入收藏
林浩
Rank: 2
等 级:论坛游民
帖 子:47
专家分:23
注 册:2011-1-12
结帖率:90.91%
收藏
已结贴  问题点数:10 回复次数:2 
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

感觉自己对了得 ,添加变量, 事件 ,消息,都按照书上的步骤进行的,编译器也一样,就是报错,好郁闷
搜索更多相关主题的帖子: 接口 鼠标 public 
2011-10-11 17:18
naruto01
Rank: 4
等 级:业余侠客
帖 子:103
专家分:280
注 册:2011-5-23
收藏
得分:10 
Point未声明么?
2011-10-11 17:40
zhaoquanyi
Rank: 2
等 级:论坛游民
帖 子:5
专家分:10
注 册:2010-8-3
收藏
得分:0 
CPoint m_ptMouse;
2011-10-13 22:12
快速回复:MFC的一个简单功能,怎么都不行,为什么呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026071 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved