#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInst,
   LPSTR lpszCmdLine,
   int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[] = "窗口";
char lpszTitle[] = "My_Windows";
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = lpszClassName; if (!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
} hwnd = CreateWindow(lpszClassName,
                  lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
} return Msg.wParam;
}
//
LRESULT CALLBACK WndProct(HWND hwnd,
  UINT message,
  WPARAM wParam,
  LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);//
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return (0);
}
我想编译这个程序, 要存为什么扩展名, 用什么编译器, VC有吗?

解决方案 »

  1.   

    这是标准的 Win32 程序,当然用 VC 可以编译 :)
    保存为 .cpp,用 VC 直接打开,它会提示你创建并保存一个项目,然后就可以编译了
      

  2.   

    我试了,不行啊
    --------------------Configuration: test - Win32 Debug--------------------
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/test.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.test.exe - 2 error(s), 0 warning(s)
      

  3.   

    http://expert.csdn.net/Expert/topic/2017/2017195.xml?temp=.8723413
      

  4.   

    不可能不行的,那你先在VC下新建一个CPP文件,然后加入你上面的代码,最后编一下,就是了一定行的
      

  5.   

    我建立了一个simple的win32 Applicaion
    然后复盖掉原来的
    再加入#indclude "StdAfx.h"
    没问题通过编译, 但是什么也没build!
    这个程序不是建立一个窗口吗?怎么什么也没建呢?
      

  6.   

    在if (!RegisterClass(&wndclass))这句前面加上:
    wndclass.cbWndExtra = 0;
      

  7.   

    搞定了
    请问这个cbWndExtra是窗口类的那种属性
    为什么要初始化这个?
    谢谢! akiko(弥弥)
      

  8.   

    cbWndExtra:(from MSDN)
    Specifies the number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASS to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA
    还是还明白(我是新手)
    没有这句“wndclass.cbWndExtra = 0;”窗口就不出现,但能通过编译
      

  9.   

    但是为什么没有赋值时, 窗口就不出现? 是不是VC的Bug啊?