我建立了几种向导都不行,比如纯控制台程序,
支持mfc的console程序空工程,等等,都错误,
而代码是别人运行过的,是windows程序,
.h里面有#include "resource.h" #include "afx....
我该怎么建立个新工程,把文件添加进去才能成功运行?
谢谢

解决方案 »

  1.   

    首先,一个工程里除了.h和.cpp文件外,还有其他文件。有resource.h多半是基于mfc的程序,你新建一个工程,里面有一个文件专门记录工程的类,用记事本查看一下,添加即可,注意将要加的文件拷到工程的目录中。
      

  2.   

    例如渥新建了一个基于console的mfc程序,它自动生成了
    resource.h给我了阿,可是还是不行。“记录工程的类“
    的文件怎么用?可以修改吗?文件我是靠背到工程目录里了阿
      

  3.   

    建一个 mfc 的工程(不要console 的),干掉原来的那几个文件(.h .cpp),再添加你的。
      

  4.   

    MFC的简单WIN32工程,去掉自产生的CPP,加上
    自己的文件,还是常看到的错误:
    e:\vc\vc_temp\new\game2\snake_and_russia.cpp(1) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
      

  5.   

    去掉#INCLUDE "STDAFX.H" 
    便是:e:\vc\vc_temp\new\game2\snake_and_russia.cpp(368) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    StdAfx.cpp
    e:\vc\vc_temp\new\game2\stdafx.cpp(5) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
    Generating Code...
    Error executing cl.exe.
      

  6.   

    这些错误一般和文件有关,
    您可以在错误提示中看见一个文件名,
    您可以找到记载文件名的地方,把它去掉或改成您自己的文件。*.pch指*.h编译过后的文件.
      

  7.   

    你的文件中有
    #include "resource.h" 
    #include "afx....
    说明它本身是一个完整的工程,只是缺少*.dsw *.dsp
    你在建立工程的时候,必须按它的名字来建立,
    因为VC是按文件名来管理工程的。
      

  8.   

    在工程中添加文件的方法:
    菜单 Project(工程)-->Add to Project(添加到工程)-->Files(文件)
    选中要加入的文件,“确定”。
    如果只是加入类(*.h 和 *cpp),就已经大功告成了.
      

  9.   

    大虾不是阿,#include "resource.h"等是没有的,是.cpp里写的。
    我只有1个cpp,3个.h(不是"resource.h","afxstd.h"),还是搞不点,
    god
      

  10.   

    如果只有*.h和*.cpp,可以用上面的方法啊.
      

  11.   

    3个.h名字都不同,根据cpp的名字?
      

  12.   

    e:\vc\vc_temp\new\game5\stdafx.cpp(5) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
    game5.cpp
    e:\vc\vc_temp\new\game5\game5.cpp(1) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
     我改成xxx.cpp为game5.cpp后,还是这样啊,指针指在#include "afxstd.h"
    上,根本没game5.pch
      

  13.   

    e:\vc\vc_temp\new\game5\stdafx.cpp(5) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
    game5.cpp
    e:\vc\vc_temp\new\game5\game5.cpp(1) : fatal error C1083: Cannot open precompiled header file: 'Debug/game5.pch': No such file or directory
     我改成xxx.cpp为game5.cpp后,还是这样啊,指针指在#include "afxstd.h"
    上,根本没game5.pch
      

  14.   

    只添加*.cpp和*.h就和工程的名字没有关系了。
    添加进工程,应该就可以用。
      

  15.   

    game5.cpp,
    snake_game.h
    russia_game.h
    canvas.h
    阿,
      

  16.   

    我这里出现的问题是找不到 资源定义的符号
    你应该还有一个和它们有关的资源文件 Resource.h-------Configuration: Game5 - Win32 Debug-----
    Compiling...
    Game5.cpp
    E:\PROWORK\Test2\Game5\Game5.cpp(30) : error C2065: 'IDS_APP_TITLE' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(31) : error C2065: 'IDC_SNAKE_AND_RUSSIA' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(76) : error C2065: 'IDI_SNAKE_AND_RUSSIA' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(81) : error C2065: 'IDI_SMALL' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(136) : error C2065: 'IDS_HELLO' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(151) : error C2065: 'ID_Russia1' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(151) : error C2051: case expression not constant
    E:\PROWORK\Test2\Game5\Game5.cpp(165) : error C2065: 'ID_Russia2' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(165) : error C2051: case expression not constant
    E:\PROWORK\Test2\Game5\Game5.cpp(180) : error C2065: 'ID_Snake' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(180) : error C2051: case expression not constant
    E:\PROWORK\Test2\Game5\Game5.cpp(197) : error C2065: 'IDM_ABOUT' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(197) : error C2051: case expression not constant
    E:\PROWORK\Test2\Game5\Game5.cpp(198) : error C2065: 'IDD_ABOUTBOX' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(200) : error C2065: 'IDM_EXIT' : undeclared identifier
    E:\PROWORK\Test2\Game5\Game5.cpp(200) : error C2051: case expression not constant
    E:\PROWORK\Test2\Game5\Game5.cpp(205) : warning C4065: switch statement contains 'default' but no 'case' labels
    Error executing cl.exe.Game5.exe - 16 error(s), 1 warning(s)
      

  17.   

    Resource.h是我建立win32 mfc console工程是产生的,你可以建个工程
    产生一个,我现在copy给你//{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by game5.rc
    //
    #define IDS_HELLO                       1// Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        101
    #define _APS_NEXT_COMMAND_VALUE         40001
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
      

  18.   

    我来说几句看看行不行:你建立一个新的工程,在你新的工程文件中把要拷贝的粘贴进去,然后在菜单项 选project->Add to project->Files 把他们添加进去就可以了。
      

  19.   

    to ArEon,我按照这样一个一个copy,结果是15个错误,1个
    wranning,但是我也包含了resourc.h了,怎么板
      

  20.   

    您应该新建一个 Win32 Application工程
    选者 典型"Hello"程序.
    工程名字用 game5
    然后,拷贝文件到目录下,
    然后,把另外三个文件加入工程。另外,
    您应该还有一个resource.h文件,定义了各种资源号
    也拷贝过来。
    应该就可以了.我这样做了,出现
    资源代号未定义错误:
    Compiling...
    Game5.cpp
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(31) : error C2065: 'IDC_SNAKE_AND_RUSSIA' : undeclared identifier
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(76) : error C2065: 'IDI_SNAKE_AND_RUSSIA' : undeclared identifier
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(151) : error C2065: 'ID_Russia1' : undeclared identifier
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(151) : error C2051: case expression not constant
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(165) : error C2065: 'ID_Russia2' : undeclared identifier
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(165) : error C2051: case expression not constant
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(180) : error C2065: 'ID_Snake' : undeclared identifier
    E:\PROWORK\Test3\Game\Game5\Game5.cpp(180) : error C2051: case expression not constant
    Error executing cl.exe.
      

  21.   

    to iicup(双杯献酒),我已经在楼上的楼上写上
    resource.h了,能看看吗?我现在式式你的方法
      

  22.   

    你的game5.cpp中用到的下列资源,不是系统自动产生的:
    IDC_SNAKE_AND_RUSSIA
    ID_Snake
    ID_Russia1
    ID_Russia2
      

  23.   

    你的game5.cpp中用到的下列资源,不是系统自动产生的:
    IDC_SNAKE_AND_RUSSIA (字符串 和 图标)
    ID_Snake             (按钮或者菜单)
    ID_Russia1           (按钮或者菜单)
    ID_Russia2           (按钮或者菜单)
    请产生它们
      

  24.   

    产生资源后,可以运行,但是显然不是想要的。
    (我胡乱的弄了三个按钮在 About窗口里. :) )