本帖最后由 VisualEleven 于 2012-10-18 09:56:08 编辑

解决方案 »

  1.   

    改了,还是不行
    error C2146: syntax error : missing ';' before identifier 'CALLBACK'
    error C2501: 'LRESULT' : missing storage-class or type specifiers
    fatal error C1004: unexpected end of file found
      

  2.   

    #include <windows.h>
    #include <tchar.h>
      

  3.   


    #include <windows.h>
    #include <tchar.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    WNDCLASSEX wcex;
    HWND hWnd;
    MSG msg;
    TCHAR szWindowClass[]=TEXT("窗口示例");
    TCHAR szTitle[]=TEXT("My Windows");
    wcex.cbSize=sizeof(WNDCLASSEX);
    wcex.style=0;
    wcex.lpfnWndProc=WndProc;
    wcex.cbClsExtra=0;
    wcex.cbWndExtra=0;
    wcex.hInstance=hInstance;
    wcex.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
    wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wcex.lpszMenuName=NULL;
    wcex.lpszClassName=szWindowClass;
    wcex.hIconSm=LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
    if(!RegisterClassEx(&wcex))
    {
    MessageBoxW(0,_T("窗口类注册失败!"),_T("窗口注册"),0);
    return 1;
    }
    hWnd=CreateWindow(
    szWindowClass,
    szTitle,
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,CW_USEDEFAULT,
    CW_USEDEFAULT,CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL
    );
    if(!hWnd)
    {
    // MessageBox(NULL,L"创建窗口失败!",_T("创建窗口"),NULL);
    return 1;
    }
    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return(int)msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    switch(message)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd,message,wParam,lParam);
    break;
    }
    return 0;
    }
      

  4.   

    很多都是拼写错误,自己好好检查一下吧
    #include <Windows.h>
    #include<tchar.h>
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    WNDCLASSEX wcex;
    HWND hWnd;
    MSG msg;
    TCHAR szWindowClass[]=L"窗口示例";
    TCHAR szTitle[]=L"My Windows";
    wcex.cbSize=sizeof(WNDCLASSEX);
    wcex.style=0;
    wcex.lpfnWndProc=WndProc;
    wcex.cbClsExtra=0;
    wcex.cbWndExtra=0;
    wcex.hInstance=hInstance;
    wcex.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
    wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wcex.lpszMenuName=NULL;
    wcex.lpszClassName=szWindowClass;
    wcex.hIconSm=LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
    if(!RegisterClassEx(&wcex))
    {
    MessageBox(NULL,_T("窗口类注册失败!"),_T("窗口注册"),NULL);
    return 1;
    }
    hWnd=CreateWindow(
    szWindowClass,
    szTitle,
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,CW_USEDEFAULT,
    CW_USEDEFAULT,CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL
    );
    if(!hWnd)
    {
    MessageBox(NULL,L"创建窗口失败!",_T("创建窗口"),NULL);
    return 1;
    }
    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return(int)msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    switch(message)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd,message,wParam,lParam);
    break;
    }
    return 0;
    }
      

  5.   

    谢谢大家的帮助。兔子大侠,在L"My Windows"这个地方还是显示 cannot convert from 'unsigned short [5]' to 'char []'
    不过楼上那个把L改成TEXT的倒是完全可以运行了。新手表示只能看懂拼写错误的更改。。其他的完全不懂啊。。
    所有的程序都要有windows.h吗,我的课本上没有这句,漏印了?
      

  6.   

    win32 程序有控制台和窗口之分 窗口程序要 windows.h
    你打开project->Settings看
    编译器中有一个‘_WINDOWS’
    连接器中有一个 “/subsystem:windows”
    表示这是一个窗口程序。
      

  7.   

    综合一下:
    #include <windows.h>
    #include <tchar.h>
    错误:
    LRESULT CALLBACK WndProch(HWND,UINT,WPARAM,LPARAM);
    WndProch -> WndProc
    错误:
    WNDCLASSEX wecx;
    看下面就知道应该是:wcex
    错误:
    TCHAR szWindowClass[] = L"窗口示例";
    TCHAR szTitle[] = L"My Windows";
    为:
    TCHAR szWindowClass[] = _T("窗口示例");
    TCHAR szTitle[] = _T("My Windows");
    错误:
    MessageBox(NULL, L"创建窗口失败!", _T("创建窗口"), NULL);
    改为:
    MessageBox(NULL, _T("创建窗口失败!"), _T("创建窗口"), MB_OK);