save as *.cpp,and compile it again

解决方案 »

  1.   

    建立一个工程(选择WIN32 APPLICATION),然后加入你的CPP文件。
      

  2.   

    可以用WIZARD直接生成你要的HELLO WORLD程序啊,
    然后看看你错在那里。
      

  3.   

    工程类型不对。选console->empty project.然后敲自己的代码(just like Trubo C)。
      

  4.   

    #define WIN32_LEAN_AND_MEAN#include <windows.h>
    #include <windowsx.h>
    #include <windows.h>
    //#include <stdafx.h>
    #include <stdio.h>
    #include <math.h>#define WINDOW_CLASS_NAME "WINCLASS1"
    //globals//functions
    //--------------------
    LRESULT CALLBACK WindowProc(HWND hwnd,
    UINT msg,
    WPARAM wparam,
    LPARAM lparam)
    { //系统信息句柄
    PAINTSTRUCT  ps;
    HDC hdc;
    //What is the message?
    switch(msg)
    {
    case WM_CREATE:
    {
    return(0);
    }break;
    case WM_PAINT:
    {
    hdc=BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps);
    return(0);
    }break;
    case WM_DESTROY:
    {
    PostQuitMessage(0); return(0);
    }break;
    default :{
    return (0); 
    //return RegisterClassEx(&winclass);
    //return hwnd;
    return DefWindowProc(hwnd, msg, wparam, lparam);
     }break;
    }
    }
    //--------------------
    //winmain函数int WINAPI WinMain(HINSTANCE hinstance,
       HINSTANCE hprevinstance,
       LPSTR lpcmdline,
       int ncmdshow)
    {
    //定义WNDCLASSEX类对象;
    WNDCLASSEX winclass;
    //定义窗口句柄
    HWND hwnd;
    //定义消息
    MSG msg; winclass.cbSize=sizeof(WNDCLASSEX);
    winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
    //winclass.style=CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc=WindowProc;
    winclass.cbClsExtra=0;
    winclass.cbWndExtra=0;
    winclass.hInstance=hinstance;
    winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    //winclass.hbrBackground=GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName=NULL;
    winclass.lpszClassName=WINDOW_CLASS_NAME;
    winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION); RegisterClassEx(&winclass);
    if(!RegisterClassEx(&winclass))
    return(0); //if(!(hwnd=// MessageBox(NULL,"there can be only one!!",
    // "my first windwos program",
    // MB_OK|MB_ICONEXCLAMATION);
    // return(0);
    //creat the window
    // TCHAR szWindowClass[MAX_LOADSTRING]; hwnd=CreateWindowEx(0,//NULL,
    //NDOW_CLASS_NAME,
    "WINCLASS",
    "your basic windwo",
    WS_OVERLAPPEDWINDOW,//WS_OVERLAPPEDWINDOW|WS_VISIBLE,
    50,50,//x,y
    400,400,//width,high
    NULL,
    NULL,
    hinstance,
    //winclass,
    NULL);
    ShowWindow(hwnd,ncmdshow);
    UpdateWindow(hwnd);
    if(!hwnd)
    {
    //ShowWindow(hwnd,ncmdshow);
    return (0);
    }
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    return (msg.wParam);
    }
    return (0);
    }
    谢谢!
      

  5.   

    把主函数改为 void main()
      

  6.   

    工程设置不对。project ->setting :link->project options 
    修改
    /subsystem:console 为 /subsystem:windows
      

  7.   

    zjp009(高手)  :我用WIZARD生成一个,调试的时候发现if(!hWnd)一句返回的为0,我前面的程序就使返回1,不知道怎么回事!
      

  8.   

    iamknight(侠客) :link里面已经是了!kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/DEMO2_1.pdb" /debug /machine:I386 /out:"Debug/DEMO2_1.exe" /pdbtype:sept
      

  9.   

    看看你这里:
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    return (msg.wParam);
                       ^^^^^^^^-^^^^^^^^^^^^
                               |---------------->程序运行一下子就结束了。
    }
    改为:
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return (msg.wParam);
      

  10.   

    cxiaobao(风子) :同样还是不显示窗口!???
      

  11.   

    问题还没解决!
    RegisterClassEx(&winclass);
    一句返回为0;
    不知道怎么回事?