以下是孙鑫老师VC++第一章中讲的··我在VS2005上运行后,窗口出不来··
#include<windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain( 
   HINSTANCE hInstance, 
   HINSTANCE hPrevInstance, 
   LPSTR lpCmdLine, 
   int nShowCmd 
   )
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;

hwnd=CreateWindow("Weixin2003","第一个windows程序",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
     }
return 0;}
LRESULT CALLBACK WinSunProc( HWND hwnd, 
UINT uMsg, 
WPARAM wParam,
LPARAM lParam )
{
switch(uMsg)
{
case WM_CHAR:
char szChar[40];
sprintf_s(szChar,"char is %d,wParam");
MessageBox(hwnd,szChar,"Weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,szChar,"Weixin2003",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"第一个windows程序",strlen("第一个windows程序"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"windows练习",strlen("windows练习"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
   if(IDYES==MessageBox(hwnd,"是否真的结束","Weixin",MB_YESNO))
   {
   DestroyWindow(hwnd);
   }
   break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam,lParam);
}
        
return 0;
 
 
}

解决方案 »

  1.   

    int WINAPI WinMain(HINSTANCE hInstance,  
       HINSTANCE hPrevInstance,  
       LPSTR lpCmdLine,  
       int nShowCmd)
    {
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadIcon(NULL,IDI_ERROR);
        wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="Weixin2003";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;    if(!RegisterClass(&wndcls))
    {
    MessageBox(NULL,"This Pro Need Windows NT!", "Error",MB_OK);
    return 0;
    }
      

  2.   

    Debug调试,出现“调试器dll.msdbg2.dll未正确安装·······”不知道成功没··
      

  3.   

    if(!RegisterClass(&wndcls))
    是注册不成功
    原来漏了:
    wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    所以注册不成功,又没有提示。所以没东西。