昨天我看了孙鑫老师的vc++深入浅出的视频第1课,按照他的程序自己重写了一遍,但是不知道为什么可以编译,运行却不能把窗口显示出来?希望哪个高人指点指点!
程序如下:
#include <windows.h>
#include <stdio.h>
 
LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
WNDCLASS  wndcls;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;//类的类型
    wndcls.lpfnWndProc=WinSunProc;//窗口过程函数
    wndcls.cbClsExtra=0;//类的附加字节数
    wndcls.cbWndExtra=0;//窗口额外的字节数
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);//图标
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);//光标
    wndcls.hbrBackground=(HBRUSH/*强制转换类型*/)GetStockObject(BLACK_BRUSH);//背景
    wndcls.lpszMenuName=NULL;
    wndcls.lpszClassName="weixin";
    RegisterClass(&wndcls);//注册窗口 HWND hwnd;//创建一个窗口
hwnd=CreateWindow("weixin","北京维新科学技术培训中心",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,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
        HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"东莞理工学院",strlen("东莞理工学院"));
    ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
         HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"东莞理工",strlen("东莞理工"));
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;
}