我得到了这个错误,我不知道为什么,我只是正确地按照他所做的去做,而他没有得到这个错误。这是代码。
//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 循环。
最佳答案
MSG 的message
成员结构是一个字段,而不是一个方法。您应该访问它而不是调用它:
while (WM_QUIT != msg.message) {
// ...
}
您的代码段中还有其他问题。首先,C++ 是一种区分大小写的语言,因此 PeekMessage()
的最后一个参数应该是 PM_REMOVE
而不是 PM_Remove
。
此外,PeekMessage()如果消息队列为空,则不会阻塞,因此您的代码最终将消耗 100% 的 CPU 内核。您可以使用 GetMessage()相反,它会在没有可用消息时阻塞,并允许您删除对 WM_QUIT
的显式测试:
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
关于c++ - Peekmessage(创建窗口循环),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16274162/