Reporting Standard Errors

The ReportError function displays a message box to report an error.

static void

ReportError(HWND hwnd, int nMessage, HRESULT hRes)

{

HDC hdc;

char szBuffer[256];

char szMessage[128];

char szError[128];

int nStrID;

// Turn the animation loop off.

fSuspended = TRUE;

// Get the high level error message.

LoadString(hAppInstance, nMessage, szMessage, sizeof(szMessage));

// We issue sensible error messages for common run time errors. For

// errors which are internal or coding errors we simply issue an

// error number (they should never occur).

switch (hRes)

{

case DDERR_EXCEPTION: nStrID = IDS_ERR_EXCEPTION; break;

case DDERR_GENERIC: nStrID = IDS_ERR_GENERIC; break;

case DDERR_OUTOFMEMORY: nStrID = IDS_ERR_OUTOFMEMORY; break;

case DDERR_OUTOFVIDEOMEMORY: nStrID = IDS_ERR_OUTOFVIDEOMEMORY; break;

case DDERR_SURFACEBUSY: nStrID = IDS_ERR_SURFACEBUSY; break;

case DDERR_SURFACELOST: nStrID = IDS_ERR_SURFACELOST; break;

case DDERR_WRONGMODE: nStrID = IDS_ERR_WRONGMODE; break;

default: nStrID = IDS_ERR_INTERNALERROR; break;

}

LoadString(hAppInstance, nStrID, szError, sizeof(szError));

// Show the "paused" display.

hdc = GetDC(hwnd);

PaintSuspended(hwnd, hdc);

ReleaseDC(hwnd, hdc);

// Convert the error code into a string.

wsprintf(szBuffer, "%s\n%s (Error #%d)", szMessage, szError,

CODEFROMHRESULT(hRes));

MessageBox(hwnd, szBuffer, WINDOW_TITLE, MB_OK | MB_APPLMODAL);

fSuspended = FALSE;

}