代码如下:#include<windows.h>
#include "stdafx.h"
long FAR PASCAL WindowFun( HWND, UINT, WPARAM, LPARAM);int WinAPI WinMain(HANDLE CurInstance,
   HANDLE PreInstance,
   LPSTR CmdParaStr,
   int ShowStyle)
{
static char ProgName[]="Myprog1_1";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
if(!PreInstance)
{
wndclass.lpszClassName=ProgName;
wndclass.hInstance=CurInstance;
wndclass.lpfnWndProc=WindowFun;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_IBEAM);
wndclass.lpszMenuName=NULL;
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.style=CS_HREDRAW | CS_VREDRAW;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
RegisterClass(&wndclass);
}
hwnd=GreateWindow(ProgName,
  ProgName,
  WS_OVERLAPPEDWINDOW,
  100,
  100,
  300,
  200,
  NULL,
  NULL,
  CurInstance,
  NULL);
Show Window(hwnd,ShowStyle);
while(GetMeasage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}long FAR PASCAL WindowFun(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
}
错误:
D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(7) : error C2146: syntax error : missing ';' before identifier 'WinMain'
D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(7) : fatal error C1004: unexpected end of file found是什么错误?
该怎么解决?

解决方案 »

  1.   

    WinAPI 改为 WINAPI 试试
      

  2.   

    agree akiko(弥弥) 
    WinAPI 改为 WINAPI 试试
      

  3.   

    MSDN上有关于C2146的解释:
    Compiler Error C2146
    syntax error : missing 'token' before identifier 'identifier'The compiler expected the given token to appear before the given identifier.TipsThis error is usually preceeded by error C2065. The most typical cause of this error is a typographical problem. For example:void main(void)
    {
       intt x; //Syntax error: missing semicolon before 'x'
    }
      

  4.   

    Compiling...
    MyPog1.cpp
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(11) : error C2731: 'WinMain' : function cannot be overloaded
            D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(7) : see declaration of 'WinMain'
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(19) : error C2440: '=' : cannot convert from 'void *' to 'struct HINSTANCE__ *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(24) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(30) : error C2065: 'GreateWindow' : undeclared identifier
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(40) : error C2440: '=' : cannot convert from 'int' to 'struct HWND__ *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(41) : error C2065: 'Show' : undeclared identifier
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(41) : error C2146: syntax error : missing ';' before identifier 'Window'
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(41) : error C2065: 'Window' : undeclared identifier
    D:\Program Files\Microsoft Visual Studio\MyProjects\MyPog1\MyPog1.cpp(42) : error C2065: 'GetMeasage' : undeclared identifier
    Error executing cl.exe.MyPog1.exe - 9 error(s), 0 warning(s)
    更多错!
      

  5.   

    #include<windows.h>long FAR PASCAL WindowFun( HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE CurInstance,HINSTANCE PreInstance,LPSTR lpCmdLine,int nShowCmd)
    {
    static char ProgName[]="Myprog1_1";
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;
    int ShowStyle = SW_SHOW;
    if(!PreInstance)
    {
    wndclass.lpszClassName=ProgName;
    wndclass.hInstance=CurInstance;
    wndclass.lpfnWndProc=WindowFun;
    wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wndclass.hCursor=LoadCursor(NULL,IDC_IBEAM);
    wndclass.lpszMenuName=NULL;
    wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.style=CS_HREDRAW | CS_VREDRAW;
    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    RegisterClass(&wndclass);
    }
    hwnd=CreateWindow(ProgName,
      ProgName,
      WS_OVERLAPPEDWINDOW,
      100,
      100,
      300,
      200,
      NULL,
      NULL,
      CurInstance,
      NULL);
    ShowWindow(hwnd,ShowStyle);
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return msg.wParam;
    }long FAR PASCAL WindowFun(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    switch(message)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    return 0;
    default:
    return DefWindowProc(hwnd,message,wParam,lParam);
    }
    }修改后的代码
    看仔细些
      

  6.   

    谢谢lygfqy(风清扬) 
    这么耐心的帮助我,VC我是初学者,以后还要多帮忙!