注册 登录
编程论坛 VC++/MFC

谁能告诉我用vc++这MFC怎么编译(步骤)

wyp19901226 发布于 2012-01-28 21:42, 2503 次点击
class CRectangle
{
public:
       CRectangle();
       virtual~CRectangle();
      void imput();
      double circum();
       double area();
private:
        double length;
        double width;
};


 

CRectangle::CRectangle()
{
}
CRectangle::~CRectangle()
{
}
void CRectangle::imput()
{
   CInputDlg Dlg;
   if(IDOK==Dlg.DoModal())
   {
   length=Dlg.m_len;
   width=Dlg.m_wid;

   }
}
double CRectangle::circum()
{
   return 2*(length+width);
}
double CRectangle:: area()
{
   return length*width;
}

#include "stdafx.h"

void  CTestView::OnMENURectangle()
{

   //TODO:Add Onmmand handler code here
   RedrawWindow();
   CRectangle Rect;
   Rect.imput();
   CString Str;
  CClientDC dc(this);
  dc.SetTextColor(RGB(0,0,255));
  Str.Format("长方形的周长为:%5.2f",Rect.circum());
  dc.TextOut(100,60,Str);
  Str.Format("长方形的面积为:%5.2f",Rect.area());
  dc.TextOut(100,80,Str);
}
我要步骤,麻烦编译下,越详细越好,最好有图,呵呵
8 回复
#2
wyp199012262012-01-28 21:44
在线等啊。。。。。
#3
wyp199012262012-01-28 21:53
这个代码是书上的,不会编译,题目是使用MFC设计一个长方形类,使用对话框输入长方形的程度,宽度,在客户端输出周长和面积,在等啊。。
#4
wyp199012262012-01-28 22:06
呜呜,。。。麻烦复制编译下,怎么创建工程的,步奏,我刚学MFC
#5
BianChengNan2012-01-29 09:18
先创建一个mfc工程,把你类的声明放到一个头文件中,实现放到一个cpp文件中,包含进工程,然后在某个button的实现代码,如
void  CTestView::OnMENURectangle()
下复制你的代码
 RedrawWindow();
   CRectangle Rect;
   Rect.imput();
   CString Str;
  CClientDC dc(this);
  dc.SetTextColor(RGB(0,0,255));
  Str.Format("长方形的周长为:%5.2f",Rect.circum());
  dc.TextOut(100,60,Str);
  Str.Format("长方形的面积为:%5.2f",Rect.area());
  dc.TextOut(100,80,Str);
#6
wyp199012262012-01-29 14:39
回复 5楼 BianChengNan
是用win32 console Application,还是用MFC Appwizard[exe],还是其他的,具体步骤,麻烦编译下,最好有图,呵呵,谢谢
#7
BianChengNan2012-01-29 15:36
以下是引用wyp19901226在2012-1-29 14:39:53的发言:

是用win32 console Application,还是用MFC Appwizard[exe],还是其他的,具体步骤,麻烦编译下,最好有图,呵呵,谢谢
你不是要mfc的工程吗?肯定是后者了。。。图肯定没有的,我这能上网不错了,抱歉啊,百度一下mfc工程的创建吧,很简单的。。。
#8
wyp199012262012-01-29 20:09
回复 7楼 BianChengNan
我编译的有错,怎么回事,麻烦看看怎么解决,我就结贴了
--------------------Configuration: 10 - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
10.cpp
MainFrm.cpp
10Doc.cpp
10View.cpp
Rectangle.cpp
F:\book\新建文件夹 (2)\Rectangle.cpp(32) : error C2653: 'CTestView' : is not a class or namespace name
F:\book\新建文件夹 (2)\Rectangle.cpp(36) : error C2660: 'RedrawWindow' : function does not take 0 parameters
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2065: 'CRectangle' : undeclared identifier
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2146: syntax error : missing ';' before identifier 'Rect'
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2065: 'Rect' : undeclared identifier
F:\book\新建文件夹 (2)\Rectangle.cpp(38) : error C2228: left of '.imput' must have class/struct/union type
F:\book\新建文件夹 (2)\Rectangle.cpp(40) : error C2673: 'OnMENURectangle' : global functions do not have 'this' pointers
F:\book\新建文件夹 (2)\Rectangle.cpp(42) : error C2228: left of '.circum' must have class/struct/union type
F:\book\新建文件夹 (2)\Rectangle.cpp(44) : error C2228: left of '.area' must have class/struct/union type
Generating Code...
执行 cl.exe 时出错.

10.exe - 1 error(s), 0 warning(s)
#9
BianChengNan2012-02-01 10:35
以下是引用wyp19901226在2012-1-29 20:09:10的发言:

我编译的有错,怎么回事,麻烦看看怎么解决,我就结贴了
--------------------Configuration: 10 - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
10.cpp
MainFrm.cpp
10Doc.cpp
10View.cpp
Rectangle.cpp
F:\book\新建文件夹 (2)\Rectangle.cpp(32) : error C2653: 'CTestView' : is not a class or namespace name
F:\book\新建文件夹 (2)\Rectangle.cpp(36) : error C2660: 'RedrawWindow' : function does not take 0 parameters
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2065: 'CRectangle' : undeclared identifier
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2146: syntax error : missing ';' before identifier 'Rect'
F:\book\新建文件夹 (2)\Rectangle.cpp(37) : error C2065: 'Rect' : undeclared identifier
F:\book\新建文件夹 (2)\Rectangle.cpp(38) : error C2228: left of '.imput' must have class/struct/union type
F:\book\新建文件夹 (2)\Rectangle.cpp(40) : error C2673: 'OnMENURectangle' : global functions do not have 'this' pointers
F:\book\新建文件夹 (2)\Rectangle.cpp(42) : error C2228: left of '.circum' must have class/struct/union type
F:\book\新建文件夹 (2)\Rectangle.cpp(44) : error C2228: left of '.area' must have class/struct/union type
Generating Code...
执行 cl.exe 时出错.

10.exe - 1 error(s), 0 warning(s)
需要在你的button按钮的cpp中 #include “类头文件”,这个真的不好说,其实特简单。。。很郁闷啊,等待一个有耐心的兄弟发个贴图教程,只需要几步
或者把你的工程发到我邮箱,帮你弄好,发给你。。。顺便给你写个简单点的步骤,273282378@

[ 本帖最后由 BianChengNan 于 2012-2-1 10:38 编辑 ]
1