?? dxutil.cpp
字號(hào):
QueryPerformanceCounter( &qwTime );
// Return the elapsed time
if( command == TIMER_GETELAPSEDTIME )
{
fElapsedTime = (double) ( qwTime.QuadPart - m_llLastElapsedTime ) / (double) m_llQPFTicksPerSec;
m_llLastElapsedTime = qwTime.QuadPart;
return (FLOAT) fElapsedTime;
}
// Return the current time
if( command == TIMER_GETAPPTIME )
{
double fAppTime = (double) ( qwTime.QuadPart - m_llBaseTime ) / (double) m_llQPFTicksPerSec;
return (FLOAT) fAppTime;
}
// Reset the timer
if( command == TIMER_RESET )
{
m_llBaseTime = qwTime.QuadPart;
m_llLastElapsedTime = qwTime.QuadPart;
m_llStopTime = 0;
m_bTimerStopped = FALSE;
return 0.0f;
}
// Start the timer
if( command == TIMER_START )
{
if( m_bTimerStopped )
m_llBaseTime += qwTime.QuadPart - m_llStopTime;
m_llStopTime = 0;
m_llLastElapsedTime = qwTime.QuadPart;
m_bTimerStopped = FALSE;
return 0.0f;
}
// Stop the timer
if( command == TIMER_STOP )
{
if( !m_bTimerStopped )
{
m_llStopTime = qwTime.QuadPart;
m_llLastElapsedTime = qwTime.QuadPart;
m_bTimerStopped = TRUE;
}
return 0.0f;
}
// Advance the timer by 1/10th second
if( command == TIMER_ADVANCE )
{
m_llStopTime += m_llQPFTicksPerSec/10;
return 0.0f;
}
if( command == TIMER_GETABSOLUTETIME )
{
fTime = qwTime.QuadPart / (double) m_llQPFTicksPerSec;
return (FLOAT) fTime;
}
return -1.0f; // Invalid command specified
}
else
{
// Get the time using timeGetTime()
static double m_fLastElapsedTime = 0.0;
static double m_fBaseTime = 0.0;
static double m_fStopTime = 0.0;
double fTime;
double fElapsedTime;
// Get either the current time or the stop time, depending
// on whether we're stopped and what command was sent
if( m_fStopTime != 0.0 && command != TIMER_START && command != TIMER_GETABSOLUTETIME)
fTime = m_fStopTime;
else
fTime = GETTIMESTAMP() * 0.001;
// Return the elapsed time
if( command == TIMER_GETELAPSEDTIME )
{
fElapsedTime = (double) (fTime - m_fLastElapsedTime);
m_fLastElapsedTime = fTime;
return (FLOAT) fElapsedTime;
}
// Return the current time
if( command == TIMER_GETAPPTIME )
{
return (FLOAT) (fTime - m_fBaseTime);
}
// Reset the timer
if( command == TIMER_RESET )
{
m_fBaseTime = fTime;
m_fLastElapsedTime = fTime;
m_fStopTime = 0;
m_bTimerStopped = FALSE;
return 0.0f;
}
// Start the timer
if( command == TIMER_START )
{
if( m_bTimerStopped )
m_fBaseTime += fTime - m_fStopTime;
m_fStopTime = 0.0f;
m_fLastElapsedTime = fTime;
m_bTimerStopped = FALSE;
return 0.0f;
}
// Stop the timer
if( command == TIMER_STOP )
{
if( !m_bTimerStopped )
{
m_fStopTime = fTime;
m_fLastElapsedTime = fTime;
m_bTimerStopped = TRUE;
}
return 0.0f;
}
// Advance the timer by 1/10th second
if( command == TIMER_ADVANCE )
{
m_fStopTime += 0.1f;
return 0.0f;
}
if( command == TIMER_GETABSOLUTETIME )
{
return (FLOAT) fTime;
}
return -1.0f; // Invalid command specified
}
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToWideCch()
// Desc: This is a UNICODE conversion utility to convert a CHAR string into a
// WCHAR string.
// cchDestChar is the size in TCHARs of wstrDestination. Be careful not to
// pass in sizeof(strDest)
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertAnsiStringToWideCch( WCHAR* wstrDestination, const CHAR* strSource,
int cchDestChar )
{
if( wstrDestination==NULL || strSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
int nResult = MultiByteToWideChar( CP_ACP, 0, strSource, -1,
wstrDestination, cchDestChar );
wstrDestination[cchDestChar-1] = 0;
if( nResult == 0 )
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertWideStringToAnsi()
// Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
// CHAR string.
// cchDestChar is the size in TCHARs of strDestination
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertWideStringToAnsiCch( CHAR* strDestination, const WCHAR* wstrSource,
int cchDestChar )
{
if( strDestination==NULL || wstrSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
int nResult = WideCharToMultiByte( CP_ACP, 0, wstrSource, -1, strDestination,
cchDestChar*sizeof(CHAR), NULL, NULL );
strDestination[cchDestChar-1] = 0;
if( nResult == 0 )
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertGenericStringToAnsi()
// Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
// CHAR string.
// cchDestChar is the size in TCHARs of strDestination
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource,
int cchDestChar )
{
if( strDestination==NULL || tstrSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
#ifdef _UNICODE
return DXUtil_ConvertWideStringToAnsiCch( strDestination, tstrSource, cchDestChar );
#else
strncpy( strDestination, tstrSource, cchDestChar );
strDestination[cchDestChar-1] = '\0';
return S_OK;
#endif
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertGenericStringToWide()
// Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
// WCHAR string.
// cchDestChar is the size in TCHARs of wstrDestination. Be careful not to
// pass in sizeof(strDest)
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertGenericStringToWideCch( WCHAR* wstrDestination, const TCHAR* tstrSource,
int cchDestChar )
{
if( wstrDestination==NULL || tstrSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
#ifdef _UNICODE
wcsncpy( wstrDestination, tstrSource, cchDestChar );
wstrDestination[cchDestChar-1] = L'\0';
return S_OK;
#else
return DXUtil_ConvertAnsiStringToWideCch( wstrDestination, tstrSource, cchDestChar );
#endif
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToGeneric()
// Desc: This is a UNICODE conversion utility to convert a CHAR string into a
// TCHAR string.
// cchDestChar is the size in TCHARs of tstrDestination. Be careful not to
// pass in sizeof(strDest) on UNICODE builds
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertAnsiStringToGenericCch( TCHAR* tstrDestination, const CHAR* strSource,
int cchDestChar )
{
if( tstrDestination==NULL || strSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
#ifdef _UNICODE
return DXUtil_ConvertAnsiStringToWideCch( tstrDestination, strSource, cchDestChar );
#else
strncpy( tstrDestination, strSource, cchDestChar );
tstrDestination[cchDestChar-1] = '\0';
return S_OK;
#endif
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToGeneric()
// Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
// TCHAR string.
// cchDestChar is the size in TCHARs of tstrDestination. Be careful not to
// pass in sizeof(strDest) on UNICODE builds
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource,
int cchDestChar )
{
if( tstrDestination==NULL || wstrSource==NULL || cchDestChar < 1 )
return E_INVALIDARG;
#ifdef _UNICODE
wcsncpy( tstrDestination, wstrSource, cchDestChar );
tstrDestination[cchDestChar-1] = L'\0';
return S_OK;
#else
return DXUtil_ConvertWideStringToAnsiCch( tstrDestination, wstrSource, cchDestChar );
#endif
}
//-----------------------------------------------------------------------------
// Name: DXUtil_LaunchReadme()
// Desc: Finds and opens the readme.txt for this sample
//-----------------------------------------------------------------------------
VOID DXUtil_LaunchReadme( HWND hWnd, TCHAR* strLoc )
{
#ifdef UNDER_CE
// This is not available on PocketPC
MessageBox( hWnd, TEXT("For operating instructions, please open the ")
TEXT("readme.txt file included with the project."),
TEXT("DirectX SDK Sample"), MB_ICONWARNING | MB_OK );
return;
#else
bool bSuccess = false;
bool bFound = false;
TCHAR strReadmePath[1024];
TCHAR strExeName[MAX_PATH];
TCHAR strExePath[MAX_PATH];
TCHAR strSamplePath[MAX_PATH];
TCHAR* strLastSlash = NULL;
lstrcpy( strReadmePath, TEXT("") );
lstrcpy( strExePath, TEXT("") );
lstrcpy( strExeName, TEXT("") );
lstrcpy( strSamplePath, TEXT("") );
// If the user provided a location for the readme, check there first.
if( strLoc )
{
HKEY hKey;
LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\DirectX SDK"),
0, KEY_READ, &hKey );
if( ERROR_SUCCESS == lResult )
{
DWORD dwType;
DWORD dwSize = MAX_PATH * sizeof(TCHAR);
lResult = RegQueryValueEx( hKey, _T("DX9SDK Samples Path"), NULL,
&dwType, (BYTE*)strSamplePath, &dwSize );
strSamplePath[MAX_PATH-1] = 0; // RegQueryValueEx doesn't NULL term if buffer too small
if( ERROR_SUCCESS == lResult )
{
_sntprintf( strReadmePath, 1023, TEXT("%s\\C++\\%s\\readme.txt"),
strSamplePath, strLoc );
strReadmePath[1023] = 0;
if( GetFileAttributes( strReadmePath ) != 0xFFFFFFFF )
bFound = TRUE;
}
}
RegCloseKey( hKey );
}
// Get the exe name, and exe path
GetModuleFileName( NULL, strExePath, MAX_PATH );
strExePath[MAX_PATH-1]=0;
strLastSlash = _tcsrchr( strExePath, TEXT('\\') );
if( strLastSlash )
{
_tcsncpy( strExeName, &strLastSlash[1], MAX_PATH );
strExeName[MAX_PATH-1]=0;
// Chop the exe name from the exe path
*strLastSlash = 0;
// Chop the .exe from the exe name
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -