关于“MyHello应用程序”的问题?

mnicjj 2010-01-21 11:22:16
因为下学期要学VC++,所以现在假期有时间就先预习了,谁知道看到第一章的试个最简单的程序都没弄出来,因为是照书打的,不过我打不出来的是因为书上说这个程序是“填空式”的,然而我不太清楚要填在哪,书上也没介绍清楚,所以就在这里提问咯,大家请别见怪哦。


// MyHello2View.h : interface of the CMyHello2View class
//
/////////////////////////////////////////////////////////////////////////////

void CMyHelloView::OnDraw(CDC*pDC)
{
CMyHelloDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:add draw code for native data here
pDC->TextOut(100,80,"Hello,我们开始VC++编程了!");
}


#if !defined(AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_)
#define AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CMyHello2View : public CView
{
protected: // create from serialization only
CMyHello2View();
DECLARE_DYNCREATE(CMyHello2View)

// Attributes
public:
CMyHello2Doc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyHello2View)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
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);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMyHello2View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CMyHello2View)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in MyHello2View.cpp
inline CMyHello2Doc* CMyHello2View::GetDocument()
{ return (CMyHello2Doc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_)


以上这程序是我已经填好的了,不过有错误,我查了代码,好像没有吧,请看下段这段代码是要填上去的:
void CMyHelloView::OnDraw(CDC*pDC)
{
CMyHelloDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:add draw code for native data here
pDC->TextOut(100,80,"Hello,我们开始VC++编程了!");
}

再看下面这段是没填上的在CMyHello2View窗口里的(也就是还没填上一段程序的代码):

// MyHello2View.h : interface of the CMyHello2View class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_)
#define AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CMyHello2View : public CView
{
protected: // create from serialization only
CMyHello2View();
DECLARE_DYNCREATE(CMyHello2View)

// Attributes
public:
CMyHello2Doc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyHello2View)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
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);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMyHello2View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CMyHello2View)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in MyHello2View.cpp
inline CMyHello2Doc* CMyHello2View::GetDocument()
{ return (CMyHello2Doc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYHELLO2VIEW_H__9A50B4C3_EF6B_4139_9983_4F8137A6098F__INCLUDED_)
...全文
114 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
mnicjj 2010-04-16
  • 打赏
  • 举报
回复
这学期上VC++的课程了,才终于搞清楚了,原来OnDraw(CDC*pDC)是填写在void CMyHelloView里,也就是添加在"视图类里(View)",而对于以上某些区民的评价我并不同意,什么“连“爬”都没学,就去学“跑”,寸步难行啊,楼主。”我一点也不赞同,这是因为我们c++已经学完了,你也应该知道学校里的教育是这学期结束了c++的课程,下学期的课程当然是会开VC++啦!

而我提前学习并没有什么不好的,并且楼上有些人说的“初学者就弄那么长的一段代码”也代表着你没怎么学过VC++吧,因为上面除红色代码的都是系统本来就有的了!

但是我也并不是说我就不学习以c语言和C++,在这方面我的确还存在许多欠缺,我会不断学习,就像你们一般如果小学一年级没读好,但又不至于留级,我相信你在很多地方还有很多学不懂的,但不可能就留级,或者假期里就一直在进行补习吧,或者你也会提前预习下学期的课程吧,况且我在我班里还是学得较好的呢!

拜托回答者如果不想回答或者回答不出,也不要打击我们“初学者”的自信好吗?
如果论坛里都净是你们这些人,那中国的编程还怎么能发展得更强大更好呢?

希望你们也学会尊重别人,我个人认为论坛是用来帮助别人的,并不是鄙视别人或打击别人的!

况且我觉得我并不没有错!!!
dfpgb 2010-01-22
  • 打赏
  • 举报
回复

void CMyHello2View::OnDraw(CDC*pDC)
{
CMyHello2Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:add draw code for native data here
pDC->TextOut(100,80,"Hello,我们开始VC++编程了!");
}

再编译下看看
康斯坦汀 2010-01-21
  • 打赏
  • 举报
回复
连“爬”都没学,就去学“跑”,寸步难行啊,楼主。

蒙飞鸿 2010-01-21
  • 打赏
  • 举报
回复
通常一个工程大概由3部分组成,一部分是.h这样的头文件,然后就是.cpp源文件,另就是资源文件。
我的理解头文件大概就是放的C里面的声明;
源文件就是放的C里面的定义和实现;
资源文件就是资源文件。。。


编译器界面上是能找到文件结构的,你对照你使用的IDE使用说明找找。

oldn123 2010-01-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 mnicjj 的回复:]
请问楼上的,CPP的位置在哪里?我不清楚哦.
[/Quote]
看来此帖要无解啦
mnicjj 2010-01-21
  • 打赏
  • 举报
回复
请问楼上的,CPP的位置在哪里?我不清楚哦.
蒙飞鸿 2010-01-21
  • 打赏
  • 举报
回复
别加到H文件里啊,加到CPP里去
mnicjj 2010-01-21
  • 打赏
  • 举报
回复
--------------------Configuration: MyHello2 - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
MyHello2.cpp
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(5) : error C2653: 'CMyHelloView' : is not a class or namespace name
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'CMyHelloDoc' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'pDoc' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'GetDocument' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2106: '=' : left operand must be l-value
MainFrm.cpp
MyHello2Doc.cpp
MyHello2View.cpp
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(5) : error C2653: 'CMyHelloView' : is not a class or namespace name
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'CMyHelloDoc' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'pDoc' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2065: 'GetDocument' : undeclared identifier
f:\jun\vc++编程自学练习\myhello2\myhello2view.h(7) : error C2106: '=' : left operand must be l-value
Generating Code...
执行 cl.exe 时出错.

MyHello2.exe - 1 error(s), 0 warning(s)

这是错误信息,没有啦,我哪有本事写那么长的代码,都说是填补式的咯,就是在某个窗口的代码上加了上面红色那段代码啊,然后运行出错了,以上是错误的信息,请懂的帮忙解决,谢谢先了.
蒙飞鸿 2010-01-21
  • 打赏
  • 举报
回复
没弄出来,是指什么现象
yuyuhongss 2010-01-21
  • 打赏
  • 举报
回复
这个要学C++,不慌学MFC。
dfpgb 2010-01-21
  • 打赏
  • 举报
回复
有什么问题啊?
蒙飞鸿 2010-01-21
  • 打赏
  • 举报
回复
初学者就去弄这么一大堆代码?
mnicjj 2010-01-21
  • 打赏
  • 举报
回复
请懂的教教我啊,谢谢了。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧