📄 ddexcept.cpp
字号:
// DDExcept.cpp : implementation of the CDDException class
//
#include "stdafx.h"
#include "Tearing Demo.h"
#include "DDExcept.h"
#include "ddraw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDDException
CDDException::CDDException(BOOL bAutoDelete /*=TRUE*/, LPCTSTR strDDMsg /*=NULL*/) :
CException(bAutoDelete),
m_strMsg(strDDMsg)
{
}
CDDException::~CDDException()
{
}
BOOL CDDException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
PUINT pnHelpContext)
{
ASSERT(lpszError != NULL && AfxIsValidString(lpszError, nMaxError));
if ((lpszError == NULL) || (!AfxIsValidString(lpszError, nMaxError))) {
// Can't work with NULL or invalid pointers...
return (FALSE);
} // if
if (pnHelpContext != NULL)
*pnHelpContext = 0;
BOOL bMsgAvailable;
if ( !m_strMsg.IsEmpty() ) {
// We have message text
lstrcpyn(lpszError,m_strMsg,nMaxError);
bMsgAvailable = TRUE;
} // if
else {
// We have no message text
lpszError[0] = '\0';
bMsgAvailable = FALSE;
} // else
return bMsgAvailable;
}
int CDDException::ReportError(UINT nType /*=MB_OK*/, UINT nError /*=0*/)
{
int nDisposition;
if ( !m_strMsg.IsEmpty() ) {
// Display a message box with an error...
CString strMsg(m_strMsg);
if ( nError ) {
// We assume the error is a DirectX HRESULT, so
// we format a string accordingly. If it turns
// out the error value is not a DirectX
// HRESULT, we will get a string with some
// system error.
CString strDDMsg;
GetDDErrorMessage(nError,strDDMsg);
strMsg += _T("\r\n") + strDDMsg;
} // if
nDisposition = AfxMessageBox(strMsg,nType);
} // if
else {
if ( !nError ) {
// Nothing to display...
nError = AFX_IDP_NO_ERROR_AVAILABLE;
} // if
nDisposition = AfxMessageBox(nError,nType);
} // else
return nDisposition;
}
int CDDException::GetDDErrorMessage( UINT nError, CString& strDDMsg)
{
// If there is a more elegant way to do this, I didn't
// think of it in time to get this demo ready! The
// error messages aren't contiguous, so a simple table
// lookup won't suffice. It would take two lookups...
// one to find the entry to the string table, and one
// to retreive the string. This seemed like a better
// alternative...
switch ( nError ) {
case DDERR_ALREADYINITIALIZED: strDDMsg = _T("DirectX error DDERR_ALREADYINITIALIZED"); break;
case DDERR_CANNOTATTACHSURFACE: strDDMsg = _T("DirectX error DDERR_CANNOTATTACHSURFACE"); break;
case DDERR_CANNOTDETACHSURFACE: strDDMsg = _T("DirectX error DDERR_CANNOTDETACHSURFACE"); break;
case DDERR_CURRENTLYNOTAVAIL: strDDMsg = _T("DirectX error DDERR_CURRENTLYNOTAVAIL"); break;
case DDERR_EXCEPTION: strDDMsg = _T("DirectX error DDERR_EXCEPTION"); break;
case DDERR_GENERIC: strDDMsg = _T("DirectX error DDERR_GENERIC"); break;
case DDERR_HEIGHTALIGN: strDDMsg = _T("DirectX error DDERR_HEIGHTALIGN"); break;
case DDERR_INCOMPATIBLEPRIMARY: strDDMsg = _T("DirectX error DDERR_INCOMPATIBLEPRIMARY"); break;
case DDERR_INVALIDCAPS: strDDMsg = _T("DirectX error DDERR_INVALIDCAPS"); break;
case DDERR_INVALIDCLIPLIST: strDDMsg = _T("DirectX error DDERR_INVALIDCLIPLIST"); break;
case DDERR_INVALIDMODE: strDDMsg = _T("DirectX error DDERR_INVALIDMODE"); break;
case DDERR_INVALIDOBJECT: strDDMsg = _T("DirectX error DDERR_INVALIDOBJECT"); break;
case DDERR_INVALIDPARAMS: strDDMsg = _T("DirectX error DDERR_INVALIDPARAMS"); break;
case DDERR_INVALIDPIXELFORMAT: strDDMsg = _T("DirectX error DDERR_INVALIDPIXELFORMAT"); break;
case DDERR_INVALIDRECT: strDDMsg = _T("DirectX error DDERR_INVALIDRECT"); break;
case DDERR_LOCKEDSURFACES: strDDMsg = _T("DirectX error DDERR_LOCKEDSURFACES"); break;
case DDERR_NO3D: strDDMsg = _T("DirectX error DDERR_NO3D"); break;
case DDERR_NOALPHAHW: strDDMsg = _T("DirectX error DDERR_NOALPHAHW"); break;
case DDERR_NOCLIPLIST: strDDMsg = _T("DirectX error DDERR_NOCLIPLIST"); break;
case DDERR_NOCOLORCONVHW: strDDMsg = _T("DirectX error DDERR_NOCOLORCONVHW"); break;
case DDERR_NOCOOPERATIVELEVELSET: strDDMsg = _T("DirectX error DDERR_NOCOOPERATIVELEVELSET"); break;
case DDERR_NOCOLORKEY: strDDMsg = _T("DirectX error DDERR_NOCOLORKEY"); break;
case DDERR_NOCOLORKEYHW: strDDMsg = _T("DirectX error DDERR_NOCOLORKEYHW"); break;
case DDERR_NODIRECTDRAWSUPPORT: strDDMsg = _T("DirectX error DDERR_NODIRECTDRAWSUPPORT"); break;
case DDERR_NOEXCLUSIVEMODE: strDDMsg = _T("DirectX error DDERR_NOEXCLUSIVEMODE"); break;
case DDERR_NOFLIPHW: strDDMsg = _T("DirectX error DDERR_NOFLIPHW"); break;
case DDERR_NOGDI: strDDMsg = _T("DirectX error DDERR_NOGDI"); break;
case DDERR_NOMIRRORHW: strDDMsg = _T("DirectX error DDERR_NOMIRRORHW"); break;
case DDERR_NOTFOUND: strDDMsg = _T("DirectX error DDERR_NOTFOUND"); break;
case DDERR_NOOVERLAYHW: strDDMsg = _T("DirectX error DDERR_NOOVERLAYHW"); break;
case DDERR_NORASTEROPHW: strDDMsg = _T("DirectX error DDERR_NORASTEROPHW"); break;
case DDERR_NOROTATIONHW: strDDMsg = _T("DirectX error DDERR_NOROTATIONHW"); break;
case DDERR_NOSTRETCHHW: strDDMsg = _T("DirectX error DDERR_NOSTRETCHHW"); break;
case DDERR_NOT4BITCOLOR: strDDMsg = _T("DirectX error DDERR_NOT4BITCOLOR"); break;
case DDERR_NOT4BITCOLORINDEX: strDDMsg = _T("DirectX error DDERR_NOT4BITCOLORINDEX"); break;
case DDERR_NOT8BITCOLOR: strDDMsg = _T("DirectX error DDERR_NOT8BITCOLOR"); break;
case DDERR_NOTEXTUREHW: strDDMsg = _T("DirectX error DDERR_NOTEXTUREHW"); break;
case DDERR_NOVSYNCHW: strDDMsg = _T("DirectX error DDERR_NOVSYNCHW"); break;
case DDERR_NOZBUFFERHW: strDDMsg = _T("DirectX error DDERR_NOZBUFFERHW"); break;
case DDERR_NOZOVERLAYHW: strDDMsg = _T("DirectX error DDERR_NOZOVERLAYHW"); break;
case DDERR_OUTOFCAPS: strDDMsg = _T("DirectX error DDERR_OUTOFCAPS"); break;
case DDERR_OUTOFMEMORY: strDDMsg = _T("DirectX error DDERR_OUTOFMEMORY"); break;
case DDERR_OUTOFVIDEOMEMORY: strDDMsg = _T("DirectX error DDERR_OUTOFVIDEOMEMORY"); break;
case DDERR_OVERLAYCANTCLIP: strDDMsg = _T("DirectX error DDERR_OVERLAYCANTCLIP"); break;
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: strDDMsg = _T("DirectX error DDERR_OVERLAYCOLORKEYONLYONEACTIVE"); break;
case DDERR_PALETTEBUSY: strDDMsg = _T("DirectX error DDERR_PALETTEBUSY"); break;
case DDERR_COLORKEYNOTSET: strDDMsg = _T("DirectX error DDERR_COLORKEYNOTSET"); break;
case DDERR_SURFACEALREADYATTACHED: strDDMsg = _T("DirectX error DDERR_SURFACEALREADYATTACHED"); break;
case DDERR_SURFACEALREADYDEPENDENT: strDDMsg = _T("DirectX error DDERR_SURFACEALREADYDEPENDENT"); break;
case DDERR_SURFACEBUSY: strDDMsg = _T("DirectX error DDERR_SURFACEBUSY"); break;
case DDERR_CANTLOCKSURFACE: strDDMsg = _T("DirectX error DDERR_CANTLOCKSURFACE"); break;
case DDERR_SURFACEISOBSCURED: strDDMsg = _T("DirectX error DDERR_SURFACEISOBSCURED"); break;
case DDERR_SURFACELOST: strDDMsg = _T("DirectX error DDERR_SURFACELOST"); break;
case DDERR_SURFACENOTATTACHED: strDDMsg = _T("DirectX error DDERR_SURFACENOTATTACHED"); break;
case DDERR_TOOBIGHEIGHT: strDDMsg = _T("DirectX error DDERR_TOOBIGHEIGHT"); break;
case DDERR_TOOBIGSIZE: strDDMsg = _T("DirectX error DDERR_TOOBIGSIZE"); break;
case DDERR_TOOBIGWIDTH: strDDMsg = _T("DirectX error DDERR_TOOBIGWIDTH"); break;
case DDERR_UNSUPPORTED: strDDMsg = _T("DirectX error DDERR_UNSUPPORTED"); break;
case DDERR_UNSUPPORTEDFORMAT: strDDMsg = _T("DirectX error DDERR_UNSUPPORTEDFORMAT"); break;
case DDERR_UNSUPPORTEDMASK: strDDMsg = _T("DirectX error DDERR_UNSUPPORTEDMASK"); break;
case DDERR_VERTICALBLANKINPROGRESS: strDDMsg = _T("DirectX error DDERR_VERTICALBLANKINPROGRESS"); break;
case DDERR_WASSTILLDRAWING: strDDMsg = _T("DirectX error DDERR_WASSTILLDRAWING"); break;
case DDERR_XALIGN: strDDMsg = _T("DirectX error DDERR_XALIGN"); break;
case DDERR_INVALIDDIRECTDRAWGUID: strDDMsg = _T("DirectX error DDERR_INVALIDDIRECTDRAWGUID"); break;
case DDERR_DIRECTDRAWALREADYCREATED: strDDMsg = _T("DirectX error DDERR_DIRECTDRAWALREADYCREATED"); break;
case DDERR_NODIRECTDRAWHW: strDDMsg = _T("DirectX error DDERR_NODIRECTDRAWHW"); break;
case DDERR_PRIMARYSURFACEALREADYEXISTS: strDDMsg = _T("DirectX error DDERR_PRIMARYSURFACEALREADYEXISTS"); break;
case DDERR_NOEMULATION: strDDMsg = _T("DirectX error DDERR_NOEMULATION"); break;
case DDERR_REGIONTOOSMALL: strDDMsg = _T("DirectX error DDERR_REGIONTOOSMALL"); break;
case DDERR_CLIPPERISUSINGHWND: strDDMsg = _T("DirectX error DDERR_CLIPPERISUSINGHWND"); break;
case DDERR_NOCLIPPERATTACHED: strDDMsg = _T("DirectX error DDERR_NOCLIPPERATTACHED"); break;
case DDERR_NOHWND: strDDMsg = _T("DirectX error DDERR_NOHWND"); break;
case DDERR_HWNDSUBCLASSED: strDDMsg = _T("DirectX error DDERR_HWNDSUBCLASSED"); break;
case DDERR_HWNDALREADYSET: strDDMsg = _T("DirectX error DDERR_HWNDALREADYSET"); break;
case DDERR_NOPALETTEATTACHED: strDDMsg = _T("DirectX error DDERR_NOPALETTEATTACHED"); break;
case DDERR_NOPALETTEHW: strDDMsg = _T("DirectX error DDERR_NOPALETTEHW"); break;
case DDERR_BLTFASTCANTCLIP: strDDMsg = _T("DirectX error DDERR_BLTFASTCANTCLIP"); break;
case DDERR_NOBLTHW: strDDMsg = _T("DirectX error DDERR_NOBLTHW"); break;
case DDERR_NODDROPSHW: strDDMsg = _T("DirectX error DDERR_NODDROPSHW"); break;
case DDERR_NOOVERLAYDEST: strDDMsg = _T("DirectX error DDERR_NOOVERLAYDEST"); break;
case DDERR_INVALIDPOSITION: strDDMsg = _T("DirectX error DDERR_INVALIDPOSITION"); break;
case DDERR_NOTAOVERLAYSURFACE: strDDMsg = _T("DirectX error DDERR_NOTAOVERLAYSURFACE"); break;
case DDERR_EXCLUSIVEMODEALREADYSET: strDDMsg = _T("DirectX error DDERR_EXCLUSIVEMODEALREADYSET"); break;
case DDERR_NOTFLIPPABLE: strDDMsg = _T("DirectX error DDERR_NOTFLIPPABLE"); break;
case DDERR_CANTDUPLICATE: strDDMsg = _T("DirectX error DDERR_CANTDUPLICATE"); break;
case DDERR_NOTLOCKED: strDDMsg = _T("DirectX error DDERR_NOTLOCKED"); break;
case DDERR_CANTCREATEDC: strDDMsg = _T("DirectX error DDERR_CANTCREATEDC"); break;
case DDERR_NODC: strDDMsg = _T("DirectX error DDERR_NODC"); break;
case DDERR_WRONGMODE: strDDMsg = _T("DirectX error DDERR_WRONGMODE"); break;
case DDERR_IMPLICITLYCREATED: strDDMsg = _T("DirectX error DDERR_IMPLICITLYCREATED"); break;
case DDERR_NOTPALETTIZED: strDDMsg = _T("DirectX error DDERR_NOTPALETTIZED"); break;
case DDERR_UNSUPPORTEDMODE: strDDMsg = _T("DirectX error DDERR_UNSUPPORTEDMODE"); break;
case DDERR_NOMIPMAPHW: strDDMsg = _T("DirectX error DDERR_NOMIPMAPHW"); break;
case DDERR_INVALIDSURFACETYPE: strDDMsg = _T("DirectX error DDERR_INVALIDSURFACETYPE"); break;
case DDERR_NOOPTIMIZEHW: strDDMsg = _T("DirectX error DDERR_NOOPTIMIZEHW"); break;
case DDERR_NOTLOADED: strDDMsg = _T("DirectX error DDERR_NOTLOADED"); break;
case DDERR_DCALREADYCREATED: strDDMsg = _T("DirectX error DDERR_DCALREADYCREATED"); break;
case DDERR_NONONLOCALVIDMEM: strDDMsg = _T("DirectX error DDERR_NONONLOCALVIDMEM"); break;
case DDERR_CANTPAGELOCK: strDDMsg = _T("DirectX error DDERR_CANTPAGELOCK"); break;
case DDERR_CANTPAGEUNLOCK: strDDMsg = _T("DirectX error DDERR_CANTPAGEUNLOCK"); break;
case DDERR_NOTPAGELOCKED: strDDMsg = _T("DirectX error DDERR_NOTPAGELOCKED"); break;
case DDERR_MOREDATA: strDDMsg = _T("DirectX error DDERR_MOREDATA"); break;
case DDERR_VIDEONOTACTIVE: strDDMsg = _T("DirectX error DDERR_VIDEONOTACTIVE"); break;
case DDERR_DEVICEDOESNTOWNSURFACE: strDDMsg = _T("DirectX error DDERR_DEVICEDOESNTOWNSURFACE"); break;
case DDERR_NOTINITIALIZED: strDDMsg = _T("DirectX error DDERR_NOTINITIALIZED"); break;
default:
// Assume it's some other kind of error message
// and format something accordingly.
{ // scope
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
strDDMsg.GetBuffer(_MAX_PATH),
0,
NULL );
strDDMsg.ReleaseBuffer();
strDDMsg = _T("System error \'") + strDDMsg + _T("\'");
} // scope
break;
} // switch
// Return the length of the string
return strDDMsg.GetLength();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -