我得到了这个错误,我不知道为什么,我只是正确地理解了他所做的事情,而他没有得到这个错误。下面是代码。
//Main application loop
MSG msg = {0};
while(WM_QUIT != msg.message())
{
if(PeekMessage(&msg, NULL, NULL, NULL, PM_Remove))
{
//Translate message
TranslateMessage(&msg);
//Dispatch message
DispatchMessage(&msg);
}
}下面是错误:
error C2064: term does not evaluate to a function taking 0 arguments
fatal error C1903: unable to recover from previous error(s); stopping compilation当我单击它时,它们都指向while循环。
发布于 2013-04-29 16:27:41
MSG结构的message成员是一个字段,而不是一个方法。你应该访问它而不是调用它:
while (WM_QUIT != msg.message) {
// ...
}您的代码片段中还存在其他问题。首先,C++是一种区分大小写的语言,因此PeekMessage()的最后一个参数应该是PM_REMOVE而不是PM_Remove。
此外,如果消息队列为空,则PeekMessage()不会阻塞,因此您的代码最终将消耗运行它的CPU核心的100%。您可以改用GetMessage(),它会在没有消息可用时阻塞,并允许您删除对WM_QUIT的显式测试
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}https://stackoverflow.com/questions/16274162
复制相似问题