读书人

新手关于消息循环成死循环的有关问题

发布时间: 2012-02-16 21:30:36 作者: rapoo

新手关于消息循环成死循环的问题,请高手指教
一个win32控制台程序:
HWND hwnd;
hwnd=CreateWindow(……
……
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
运行以后,APP.EXE的CPU占有率接近100,导致越来越来,后改成
MSG msg;
bool bRet;
while((bRet=GetMessage(&msg,hwnd,0,0)) != 0)
{
if(bRet == -1)
{
return -1;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
反而警告: warning C4800: 'int ' : forcing value to bool 'true ' or 'false ' (performance warning)
warning C4806: '== ' : unsafe operation: no value of type 'bool ' promoted to type 'const int ' can equal the given constant
Linking...还是出现上面出现的情况。。。。点解啊。。。有什么其他办法处理吗?

[解决办法]
你得到消息,但没有处理消息,这个是造成 100%的原因

就相当于 while (1);

警告是你数据类型不匹配

读书人网 >C++

热点推荐