1

我得到了这个错误,我不知道为什么,我只是正确地按照他的做法,他没有得到这个错误。这是代码。

 //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 循环。

4

1 回答 1

8

The message member of the MSG structure is a field, not a method. You should access it instead of calling it:

while (WM_QUIT != msg.message) {
    // ...
}

There are other issues in your code snippet. First, C++ is a case-sensitive language, so the last argument to PeekMessage() should be PM_REMOVE instead of PM_Remove.

In addition, PeekMessage() does not block if the message queue is empty, so your code will end up consuming 100% of the CPU core it runs on. You can use GetMessage() instead, which blocks if no message is available and would allow you to remove the explicit test for WM_QUIT:

MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
于 2013-04-29T08:27:40.890 回答