Game Development Reference
In-Depth Information
// An instance of your game is already running.
ShowWindow(hWnd, SW_SHOWNORMAL);
SetFocus(hWnd);
SetForegroundWindow(hWnd);
SetActiveWindow(hWnd);
return false;
}
}
return true;
}
The Windows CreateMutex() API is used to gate only one instance of your game
to the window detection code, the FindWindow() API. You call it with your game
s
title, which uniquely identifies your game. A mutex is a process synchronization
mechanism and is common to any multitasking operating system. It is guaranteed
to create one mutex with the identifier gameTitle for all processes running on the
system. If it can
'
'
t be created, then another process has already created it. You
'
ll learn
more about these in Chapter 20.
Checking Hard Drive Space
Most games need a bit of free secondary storage space for saving games, caching data
from the DVD-ROM drive, and other temporary needs. Here
s a bit of code you can
use to find out if your player has enough storage space for those tasks:
'
bool CheckStorage(const DWORDLONG diskSpaceNeeded)
{
// Check for enough free disk space on the current disk.
int const drive = _getdrive();
struct _diskfree_t diskfree;
_getdiskfree(drive, &diskfree);
unsigned __int64 const neededClusters =
diskSpaceNeeded /
( diskfree.sectors_per_cluster * diskfree.bytes_per_sector );
if (diskfree.avail_clusters < neededClusters)
{
// if you get here you don
'
t have enough disk space!
GCC_ERROR(
CheckStorage Failure: Not enough physical storage.
);
return false;
}
return true;
}
 
 
Search WWH ::




Custom Search