Here's a dll that has commands to help let you know when your program loses it's resources (ie: alt-tab, ctrl-alt-del, etc... ) in a fullscreen or windowed state. Not perfect, but better then nothing. [ <---
EDIT: Force Reloading is better! Scroll down the thread to see my example of Force Reloading ]
Checking for a lost device in the exclusive fullscreen state can be a little bit fiddly. For example,
sometimes when my app is in a fullscreen state, on windows Vista, I can hit ctrl-alt-tab and then select the "Start Task Manager" real quick. Then for some reason, my DBPro app will not detect that it no longer has focus and continue through the code and then
crash as if it didn't allow it to have time to reset the lost device. For the fullscreen part in my example code, I use "Screen Invalid" to detect when the DBPro program has focus or not. "Screen Invalid" needs to halt the DBPro program and wait until it has focus again, restore the window and then reload graphics, etc... before using those resources again.
* another weird situation with fullscreen mode, is that I have to check for a "device lost"
again before I reload my resources. Otherwise, it won't work for me right.
Mabie somebody can make this example bullet proof. Or mabie this may help to get the DBPro's Source Code fix'd in the future to have a solid Device Lost functionality.
Seems to work great in regular window mode. This functionality comes directly from DBPro. This dll returns a 1 on the commands when the DBPro callback routines are called and used by DBPro's internals. Otherwise, they return 0. DLL source code below under DBPro Example code.
I have attached a .rar archive on this post.
It includes:
-
plugins-user folder:
DeviceLost.dll
-
Keywords folder:
DeviceLost.ini
- DeviceLost.DBPRO
- DeviceLost.DBA
- grass.bmp ( from DBPro's included Media )
- Application.exe ( compiled DeviceLost Program )
DBPro Device Lost Example Code:
[ Set WindowModeOn to 0 for windowed mode or 1 for fullscreen mode ]
sync on
sync rate 60
autocam off
GLOBAL App_WindowMode as INTEGER
App_WindowModeOn=1
if App_WindowModeOn=0
Set Display Mode DESKTOP WIDTH(),DESKTOP HEIGHT(),0
set window off
else
set window on
endif
rem load graphics
Load_GFX()
rem Device Lost Commands
remstart
res1=DEVICE LOST()
res2=DEVICE NOTRESET() ` Not sure if needed
res3=DEVICE RESET()
remend
DO
text 0,0,"Device Lost Test"
paste image 1, 0, 20
if DEVICE LOST()=1
SYNC SLEEP 1 ` Sync sleep to be nice to the cpu
if App_WindowModeOn=0 ` FULLSCREEN MODE
MINIMIZE WINDOW
While DEVICE RESET()=0
` Waiting for reset
sync
EndWhile
While Screen Invalid()=0
sync
EndWhile
RESTORE WINDOW
if DEVICE LOST()=1
` 2nd DEVICE LOST() check. It doesn't work for me without. Dont know why.
sync
endif
else ` Windowed MODE
While DEVICE RESET()=0
` Waiting for reset
sync
EndWhile
endif
` Reload/recreate all
Load_GFX()
SYNC SLEEP 0
endif
SYNC
LOOP
Function Load_GFX()
if image exist(1)
delete image 1
endif
load image "grass.bmp", 1, 1
EndFunction
C++ Code for the DeviceLost.dll
[DeviceLost.h]
#define STRICT
#include <windows.h>
#include "globstruct.h"
#define DLLEXPORT __declspec ( dllexport )
[DeviceLost.cpp]
#include "DeviceLost.h"
// Globals
int gDeviceLost;
int gDeviceNotReset;
int gDeviceReset;
// Device lost handling
DLLEXPORT void D3DDeviceLost(void) // DBPro Callback
{
gDeviceLost = 1;
}
DLLEXPORT void D3DDeviceNotReset(void) // DBPro Callback
{
gDeviceNotReset = 1;
}
DLLEXPORT void D3DDeviceReset(void) // DBPro Callback
{
gDeviceReset = 1;
}
DLLEXPORT int DeviceLost()
{
if (gDeviceLost)
{
gDeviceLost = 0;
return 1;
}
return 0;
}
DLLEXPORT int DeviceNotReset()
{
if (gDeviceNotReset)
{
gDeviceNotReset = 0;
return 1;
}
return 0;
}
DLLEXPORT int DeviceReset()
{
if (gDeviceReset)
{
gDeviceReset = 0;
return 1;
}
return 0;
}
Edit: lol , I just realized the grass.bmp is actaully a picture of dirt or rock. Don't know where I got it from.