刚学VC++编写了一个窗口,但是关闭按钮没用,求各位大神帮忙,问题关键在WM_CLOSE消息不起作用
#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 wndcls;
MSG msg;
HWND hwnd;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="SUNXIN2006";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
hwnd=CreateWindow("SUNXIN2006","hello",
WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0));
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char code is %d",wParam);
MessageBox(hwnd,szchar,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click!","message",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,80,"我是周方武",strlen("我是周方武"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
// if (IDYES==MessageBox(hwnd,"是否真的要关闭程序?","message",MB_YESNO))
// {
// }
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}