Krootushas 0 Newbie Poster

Hello. I would like to temporarelly store incomming win32 messages in a buffer. Then process all messages from that buffer manually. I actually have successfully stored and processed meesages in a buffer but I dont know if this is a best solution for my problem.

LRESULT CALLBACK WinProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

    buffer.push_back(message(hWnd,msg,wParam,lParam));

    return 0;
}

void Process ( ) {

    for(unsigned int i = 0; i < buffer.size(); i++)

        DefWindowProc(buffer[i].hWnd,buffer[i].msg,buffer[i].wParam,buffer[i].lParam);
}

The code above is one of my atempts to store messages in a buffer. The problem with this approach is it just doesn't work.
The window does not show up. I assume its because of the lack of processed messages. I have two theories why this is happenning :
1) The DefWindowProc is called outside WinProc function which is causing some kind unexpected behavior.
2) WinProc always return 0 which means I handled the message. And when I try to process them the DefWindowProc discards them because they are old.

The next attemp :

while(GetMessage(...)) {

    TranslateMessage(&msg);

    buffer.push_back(message(hWnd,msg,wParam,lParam));
}


void Process ( ) {

    for(unsigned int i = 0; i < buffer.size(); i++)

        DispatchMessage(buffer[i]);
}

LRESULT CALLBACK WinProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

    return DefWindowProc(buffer[i].hWnd,buffer[i].msg,buffer[i].wParam,buffer[i].lParam);
}

The recent code actually works fine(as far as I tested) but my concern is that messages in the buffer are not fully formed and they may be missing some information which will be filled in, in DispatchMessage function.

Please share your thoughts on both attempts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.