在VC++技术内幕一书中,在讲述应用框架时给出一例子如下:
myapp.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyFrame : public CFrameWnd
{
public:
MyFrame();
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
myapp.cpp
#include <afxwin.h>
#include "myapp.h"
CMyApp NEAR theApp;
BOOL CMyApp::InitInstance();
{        //error C2447: missing function header (old-style formal list?) m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
    ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()
CMyFrame::MyFrame()
{
Creat("AfxFrameOrView","MYAPP Application");//error C2065: 'Creat' : undeclared identifier
}
void CMyFrame::OnLButtonDown(UINT nFlags,CPoint point)
{
TRACE("Entering CMyFrame::OnLButtonDown - %1x,%d,%d\n",
(long)nFlags,point.x,point.y);
}
void CMyFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(0,0,"Hello, world!");
}
但是编译时出现如下错误:
error C2447: missing function header (old-style formal list?)
error C2065: 'Creat' : undeclared identifier
错误所处的位置如程序所示。
请我的vc是6.0版,书是94年清华版的其中的例子可能是 基于vc1.0的

解决方案 »

  1.   

    Creat should be Create .you spell wrong.
    try again will be ok.
      

  2.   

    版本太旧了
    给你一个新版本的hello worldHello.h
    class CMyApp : public CWinApp
    {
    public:
        virtual BOOL InitInstance ();
    };class CMainWindow : public CFrameWnd
    {
    public:
        CMainWindow ();protected:
        afx_msg void OnPaint ();
        DECLARE_MESSAGE_MAP ()
    };Hello.cpp
    #include <afxwin.h>
    #include "Hello.h"CMyApp myApp;/////////////////////////////////////////////////////////////////////////
    // CMyApp member functionsBOOL CMyApp::InitInstance ()
    {
        m_pMainWnd = new CMainWindow;
       m_pMainWnd->ShowWindow (m_nCmdShow);
        m_pMainWnd->UpdateWindow ();
        return TRUE;
    }/////////////////////////////////////////////////////////////////////////
    // CMainWindow message map and member functionsBEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
        ON_WM_PAINT ()
    END_MESSAGE_MAP ()CMainWindow::CMainWindow ()
    {
        Create (NULL, _T ("The Hello Application"));
    }void CMainWindow::OnPaint ()
    {
        CPaintDC dc (this);
        
        CRect rect;
        GetClientRect (&rect);    dc.DrawText (_T ("Hello, MFC"), -1, &rect,
            DT_SINGLELINE &brvbar; DT_CENTER &brvbar; DT_VCENTER);
    }
      

  3.   

    BOOL CMyApp::InitInstance(); 去掉“;”号
    "Creat"改为"Create"
      

  4.   

    hanwg()的方法在编译单个的cpp文件时,通过,但是在编译全部文件时,却出现下面的错误,EvenLee(evenlee)朋友的程序也是同样的问题,请问是怎么回事?
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/hello.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.hello.exe - 4 error(s), 0 warning(s)
      

  5.   

    1.建立一个空的win32 application 工程;
    2.加入文件hello.h, hello.cpp;
    3.在该工程中,对菜单操作 project->settings,出现属性表,在general属性页,
      在下拉框中选中 :use MFC in a shared dll(默认选中的是:not using MFC)
      

  6.   

    我直接在原来的项目中按照 wxzfox(乐乐)的建议修改出现下面的错误,但是要是重建一个空的win32 application 工程就没这些错误,为什么?
    --------------------Configuration: hello - Win32 Debug--------------------
    Linking...
    msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
    Debug/hello.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.hello.exe - 2 error(s), 0 warning(s)
      

  7.   

    你原来建的是什么工程,win32 console application 和 win32 application的主程序入口不一样,一个是main, 一个是WinMain,在控制台模式下,一部分windows的GDI函数不能使用。
      

  8.   

    你肯定用的是Win32 console application
    也不是没有办法project->settings,在link属性页,在Category下拉框,选中Output, 然后在Entry-point symbol 下方的编辑框中写入 WinMainCRTStartup,然后再编译执行