请看这个程序
#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 nCmdShow
)
{
WNDCLASS win2007;
win2007.cbClsExtra=0;
win2007.cbWndExtra=0;
win2007.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
win2007.hCursor=LoadCursor(NULL,IDC_CROSS);
win2007.hIcon=LoadIcon(NULL,IDI_ERROR);
win2007.hInstance=hInstance;
win2007.lpfnWndProc=WinSunProc;
win2007.lpszClassName="sunweihang";
win2007.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&win2007);
HWND hwnd;
hwnd=CreateWindow("win2007","孙伟航",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[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"swh",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","swh",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,"是否真的结束?","swh",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
编译的时候没有任何错误,可是为什么就是不能运行呢?
本人初学者,请指教!