DDERR_SURFACELOSTand PeekMessage

Started by
2 comments, last by j_north 22 years, 10 months ago
I''m trying to execute a simple DD program using C++. I have set up a primary surface in one class and have one sprite class that contains a DDS. The problem is, when the message loop uses GetMessage to process the messages, DD workes fine, but only animates when the GetMessage function falls through. When I change this to PeekMessage, I keep getting DDERR_SURFACELOST when I try to Blt. Performing a ->Restore and loading the image isn''t working on the sprite surface. Can anyone help?
Advertisement
Even when using PeekMessage, you must still take the messages out of the message queue. So if you are leaving the messages in the queue when using PeekMessage you must do something like this:

while {GameRunning}
while (PeekMessage(&msg, hWnd, 0, 0, PM_NOREMOVE))
{
GetMessage(&msg,hWnd,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Do drawing etc.
}

If you aren''t using the PM_NOREMOVE flag, then I''m not sure why it''s not working.
Good technique, but I''m still getting the same error. What about a DD surace could PeekMessage affect that GetMessage won''t? I''ve never had a problem with a message loop before.
PeekMessage shouldn''t do anything to affect a DDS... strange...

Does it happen every time you blt or only before/after/around a certain msg has been received?

btw, the following message loop gets rid of the GetMessage call (but works the same way):

  while (game_running){   while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {      if (msg.message == WM_QUIT)         game_running = false;      TranslateMessage(&msg);      DispatchMessage(&msg);   };   // Do drawing and other game-stuff here};  


This topic is closed to new replies.

Advertisement