vc++窗口死循环
代码:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinsunPro
(
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 wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=HBRUSH(GetStockObject(WHITE_BRUSH));
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinsunPro;
wndclass.lpszClassName="chenzhiang";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW |CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("chenzhiang","First Window",WS_OVERLAPPEDWINDOW,
// CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
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 WinsunPro
(
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 %c",char(wParam));
MessageBox(hwnd,szchar,"char msg",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked!","mouse msg",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"You clicked left button!",strlen("You clicked left button!"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC Hdc;
PAINTSTRUCT ps;
Hdc=BeginPaint(hwnd,&ps);
TextOut(Hdc,0,0,"chenzhiang's first window!",strlen("chenzhiang's first window!"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"Are you sure to quit?","close",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
运行后只显示窗口,不能接受消息,用断点调试估计是死循环,
请帮忙找出错误的地方,和原因。
谢谢