新建了一个win32 console Application 程序
将其默认主循环代码
“while (GetMessage(&msg, NULL, 0, 0))”
改为
“while(msg.message != WM_QUIT)”
后
编译没有error,但有“warning C4700: uninitialized local variable 'msg' used”
F5出现提示:“Run-Time Check Failure #3 - The variable 'msg' is being used without being initialized.”
msg需要怎样初始化?
答案:
1. 在进入while循环之前,先GetMessage(&msg,NULL,NULL,NULL);一次,让msg初始化。在循环体中应该再调用GetMessage或PeekMessage,否则就真成了死循环了。
2.
MSG msg;
msg.message = WM_NULL;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);