Restoring surfaces...
How can I effectively restore my DirectDraw surfaces and my game so that if some fool presses ALT-TAB and then he wants to go back to the game, everything will continue to run. I''m talking about fullscreen games. I know you have to use the messages WM_ACTIVATEAPP or WM_ACTIVATE to track whether the application has the focus. I made my game pause when it doesn''t have the focus, but when I try to restore the game, all the video memory is lost and the game crashes. Does anyone know a lot about IDirectDrawSurface7::Restore()? I think that''s how I''m supposed to restore my surfaces but I can''t get it to work properly.
Thanks,
Al
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
The restore in DX only restores the allocate surface memory, not the contents so you will need to reload the bitmaps onto the surface.
Basically, there is a difference to WM_ACTIVATEAPP and WM_ACTIVATE.
WM_ACTIVATEAPP occurs when another program of another thread is activated.
WM_ACTIVATE occurs when your appl loses the focus (ie a messagebox comes up)
WM_ACTIVATEAPP will call WM_ACTIVATE first, BTW. Try trapping the message and outputting it to a file to get a better understanding.
So what you have to do there is to use the WPARAM parameter to determine whether you are getting or losing the focus when you receive a WM_ACTIVATEAPP or WM_ACTIVATE. (I don''t have the exact details there. Check the MSDN)
You can restore your surfaces there but first check there are lost first cause WM_ACTIVATEAPP also calls WM_ACTIVATE.
For a really large project, my solution is to have a function pointer that you set during the various course of the game where the bitmaps are to be loaded from (ie when u switch levels). Then the call in windproc handler will not change, just set the pointer to a different function in the beginning of each level.
Hope that helps
Basically, there is a difference to WM_ACTIVATEAPP and WM_ACTIVATE.
WM_ACTIVATEAPP occurs when another program of another thread is activated.
WM_ACTIVATE occurs when your appl loses the focus (ie a messagebox comes up)
WM_ACTIVATEAPP will call WM_ACTIVATE first, BTW. Try trapping the message and outputting it to a file to get a better understanding.
So what you have to do there is to use the WPARAM parameter to determine whether you are getting or losing the focus when you receive a WM_ACTIVATEAPP or WM_ACTIVATE. (I don''t have the exact details there. Check the MSDN)
You can restore your surfaces there but first check there are lost first cause WM_ACTIVATEAPP also calls WM_ACTIVATE.
For a really large project, my solution is to have a function pointer that you set during the various course of the game where the bitmaps are to be loaded from (ie when u switch levels). Then the call in windproc handler will not change, just set the pointer to a different function in the beginning of each level.
Hope that helps
Thanks for the advice, Void. I already knew how to get the focus and I got my program to restore the back and primary surfaces so switching between programs during certain parts of the game doesn''t cause it to crash.
That''s a great idea about the function pointer. I''ll try it out.
Later,
Al
That''s a great idea about the function pointer. I''ll try it out.
Later,
Al
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement