Frage

So i've been reading up on the Win32 message pump and I was curious if the DispatchMessage() function deals with the entire message queue, or just the message at the top of the queue?

For example, i've seen loops such as:

while(true) 
{

    MSG  msg;

    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        if (msg.message == WM_QUIT) 
        {
            break;
        } 
        else 
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    } 

    do 
    {   
    } while (clock.getTimeDeltaMilliseconds() < 1.66f); // cap at 60 fps

    // run frame code here
}

In this example would every message get processed or does this loop structure cause only one message to be processed per frame?

If it does deal with only one message at a time, should I change the if(PeekMessage) statement to a while loop to ensure all messages are handled?:

while(true) 
{

    MSG  msg;

    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        if (msg.message == WM_QUIT) 
        {
            return;
        } 
        else 
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    } 

    do 
    {   
    } while (clock.getTimeDeltaMilliseconds() < 1.66f); // cap at 60 fps

    // run frame code here
}
War es hilfreich?

Lösung

It only deals with the top message. MSG is a structure that holds information about one message, filled when you call GetMessage or PeekMessage, the former being a blocking function. You then pass that information about the one message to DispatchMessage.

If you want to handle the entire message queue before whatever else you do in the loop, you should enclose that part in a loop.

Andere Tipps

DispatchMesasge has nothing to do with message queue, it only process the message that you pass to it, actual function that remove message from message queue is PeekMessage and it only remove or peek one message, so you are right you should use a while loop to process all messages in the queue

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top