一个小程序不明白
//今天编了个小程序,是输出字符的ASCII的,可是程序运行几次后就会弹出一个警告窗口说程序无法执行,然后就自动关闭了,不明白,还请高手赐教!
#include< windows.h >
#include< stdio.h >
LRESULT CALLBACK WndSHAGUOProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_QUESTION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndSHAGUOProc;
wndclass.lpszClassName = "shaguo";
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd = CreateWindow("shaguo","江大沙锅 ",WS_OVERLAPPEDWINDOW,0,0,
200,100,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 WndSHAGUOProc(
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 shaguo[20];
sprintf(shaguo,"字符 %c 的 ASCII 是 %d ",wParam,wParam);
MessageBox(hwnd,shaguo,"shaguo",0);
break;
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"查看字符ASCII",sizeof("查看字符ASCII"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"真的退出?"," 字符 ASCII 查看",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hwnd,uMsg,wParam,lParam));
}
return 0;
}