?? asl_utils.cpp
字號:
//-----------------------------------------------------------------------------
//
// ____ Azure Star Game Engine 藍星游戲引擎 ____
//
// Copyright (c) 2006, 藍星工作室
// All rights reserved.
//
// 文件名稱: asl_utils.cpp
// 摘 要: ASL庫實用組件實現(xiàn)
//
// 當前版本: 1.0
// 作 者: 湯 祺
// 創(chuàng)建日期: 2006-7-15
//
//-----------------------------------------------------------------------------
#include "asl_utils.h"
namespace ASL
{
//-----------------------------------------------------------------------------
// 函數(shù)名: EnableMemoryLeakCheck()
// 功 能: 打開內存泄漏檢測(僅Debug版起作用)
// 參 數(shù): [void] - 無
// 返回值: [void] - 無
//-----------------------------------------------------------------------------
void EnableMemoryLeakCheck()
{
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
}
//-----------------------------------------------------------------------------
// 函數(shù)名: CheckDXVersion8()
// 功 能: 檢測DirectX版本是否超過8
// 參 數(shù): [void] - 無
// 返回值: [bool] - DirectX版本是否超過8
//-----------------------------------------------------------------------------
bool CheckDXVersion8(void)
{
HINSTANCE hD3D8DLL = LoadLibrary("D3D8.DLL");
if (hD3D8DLL == NULL)
{
return false;
}
else
{
FreeLibrary(hD3D8DLL);
return true;
}
}
//-----------------------------------------------------------------------------
// 函數(shù)名: GetAppPath()
// 功 能: 取應用程序路徑
// 參 數(shù): [void] - 無
// 返回值: [LPCSTR] - 應用程序路徑
//-----------------------------------------------------------------------------
LPCSTR GetAppPath(void)
{
static char szAppPath[MAX_PATH] = { '\0' };
if (szAppPath[0] == '\0')
{
int i;
GetModuleFileName(GetModuleHandle(NULL), szAppPath, MAX_PATH);
for(i = (int)strlen(szAppPath) - 1; i > 0; --i)
{
if(szAppPath[i] == '\\')
{
break;
}
}
szAppPath[i + 1] = '\0';
}
return szAppPath;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: GetAbsPath()
// 功 能: 取應用程序目錄下某子目錄的絕對路徑
// 參 數(shù): [szDir] - 子目錄名
// 返回值: [LPCSTR] - 子目錄的絕對路徑
//-----------------------------------------------------------------------------
LPCSTR GetAbsPath(LPCSTR szDir)
{
static char szAbsPath[MAX_PATH];
strcpy(szAbsPath, GetAppPath());
strcat(szAbsPath, szDir);
return szAbsPath;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: IsMMX()
// 功 能: 檢測CPU是否支持MMX指令
// 參 數(shù): [void] - 無
// 返回值: [bool] - CPU是否支持MMX指令
//-----------------------------------------------------------------------------
bool IsMMX()
{
int ismmx = 0;
__asm
{
mov eax, 1
cpuid
test edx, 0x00800000
jz _notmmx
mov ismmx, 1
_notmmx:
}
return ismmx == 1;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: CreateFontFast()
// 功 能: 快速創(chuàng)建字體
// 參 數(shù): [face] - 字體名稱
// [height] - 文字高度
// [bold] - 是否粗體
// [italic] - 是否斜體
// [underline] - 是否下劃線
// 返回值: [HFONT] - 字體句柄
//-----------------------------------------------------------------------------
HFONT CreateFontFast(LPCSTR face, int height, bool bold, bool italic, bool underline)
{
LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
strcpy(lf.lfFaceName, face);
lf.lfHeight = height;
if (face[0] < 0)
{
lf.lfCharSet = GB2312_CHARSET;
}
if (bold)
{
lf.lfWeight = FW_BOLD;
}
if (italic)
{
lf.lfItalic = TRUE;
}
if (underline)
{
lf.lfUnderline = TRUE;
}
return CreateFontIndirect(&lf);
}
//-----------------------------------------------------------------------------
// 函數(shù)名: Bit16To64()
// 功 能: 將16位數(shù)擴展為64位(拷貝4份)
// 參 數(shù): [val] - 待擴展的16位數(shù)
// 返回值: [__int64] - 擴展后的64位數(shù)
//-----------------------------------------------------------------------------
__int64 Bit16To64(WORD val)
{
__int64 bit64 = val;
return bit64 | (bit64 << 16) | (bit64 << 32) | (bit64 << 48);
}
LPCSTR ASLFileException::GetErrorMessage(void) const
{
static char szMessage[128];
switch(m_Cause)
{
case Generic:
sprintf(szMessage, "使用文件 %s 時發(fā)生錯誤", m_szFileName);
break;
case OpenFailed:
sprintf(szMessage, "打開文件 %s 失敗", m_szFileName);
break;
case WriteFailed:
sprintf(szMessage, "寫文件 %s 失敗", m_szFileName);
break;
case BadFormat:
sprintf(szMessage, "文件 %s 格式無效", m_szFileName);
break;
}
return szMessage;
}
LPCSTR ASLDirectXException::GetErrorMessage(void) const
{
static char szMessage[228];
switch (m_DirectType)
{
case DirectX:
sprintf(szMessage, "DirectX錯誤: %s\n錯誤代號: %d", m_szDesc, m_hr);
break;
case DirectDraw:
sprintf(szMessage, "DirectDraw錯誤: %s\n錯誤代號: %d", m_szDesc, m_hr);
break;
case DirectMusic:
sprintf(szMessage, "DirectMusic錯誤: %s\n錯誤代號: %d", m_szDesc, m_hr);
break;
case DirectSound:
sprintf(szMessage, "DirectSound錯誤: %s\n錯誤代號: %d", m_szDesc, m_hr);
break;
case DirectInput:
sprintf(szMessage, "DirectInput錯誤: %s\n錯誤代號: %d", m_szDesc, m_hr);
break;
}
return szMessage;
}
} // namespace ASL
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -