Files
Slnkdwf/SlnkDWFImpl/JglUtil.cpp
Jos Groot Lipman 6ddcc6bf77 UWVA#14391 Encrypted/zip/ SLNKDWF 2.20
svn path=/Slnkdwf/trunk/; revision=12492
2008-09-02 13:48:16 +00:00

95 lines
2.1 KiB
C++

#include "stdafx.h"
#include <math.h>
//#include "JglUtil.h"
int CmyTimer::level=0;
HRESULT myAtlReportError(const CLSID & clsid, LPCTSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf;
char szBuffer[1024]; // Maximum voor wvsprintf!!
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
if (errno)
nBuf = _snprintf(szBuffer, sizeof(szBuffer),
"%s\n(errno %d)", szBuffer, errno);
if (GetLastError())
nBuf = _snprintf(szBuffer, sizeof(szBuffer),
"%s\n(lasterror may not apply) %d: %s", szBuffer, GetLastError(), myGetLastErrorMsg());
// ASSERT(nBuf < _countof(szBuffer));
va_end(args);
myTRACE(szBuffer);
return AtlReportError(clsid, szBuffer);
}
const CString myCString(LPCTSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf;
char szBuffer[1024]; // Maximum voor wvsprintf!!
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
va_end(args);
return CString(szBuffer);
}
void myDoTRACE(LPCTSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf;
char szBuffer[512];
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
// ASSERT(nBuf < _countof(szBuffer));
OutputDebugString(szBuffer);
va_end(args);
}
const char* myGetLastErrorMsg()
{
static char MsgBuf [_MAX_PATH];
::FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &MsgBuf,
sizeof(MsgBuf),
NULL
);
return MsgBuf;
}
long myRound(double const &x) {
ATLASSERT(x >= LONG_MIN-0.5);
ATLASSERT(x <= LONG_MAX+0.5);
if (x >= 0)
return (long) (x+0.5);
return (long) (x-0.5);
}
BOOL isDarkRGB(COLORREF const &clr)
{
return pow(255.0 - GetRValue(clr),2) +
pow(255.0 - GetGValue(clr),2) +
pow(255.0 - GetBValue(clr),2) >
pow(GetRValue(clr), 2.0) +
pow(GetGValue(clr), 2.0) +
pow(GetBValue(clr), 2.0);
}