102 lines
2.1 KiB
C++
102 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);
|
|
|
|
CString s;
|
|
s.FormatV(lpszFormat, args);
|
|
|
|
if (errno)
|
|
{
|
|
CString s2;
|
|
s2.Format("%s\n(errno %d)", s, errno);
|
|
s = s2;
|
|
}
|
|
|
|
if (GetLastError())
|
|
{
|
|
CString s2;
|
|
s2.Format("%s\n(lasterror may not apply) %d: %s", s, GetLastError(), myGetLastErrorMsg());
|
|
s = s2;
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
myTRACE(s);
|
|
return AtlReportError(clsid, s);
|
|
}
|
|
|
|
const CString myCString(LPCTSTR lpszFormat, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, lpszFormat);
|
|
|
|
CString s;
|
|
s.FormatV(lpszFormat, args);
|
|
|
|
va_end(args);
|
|
|
|
return s;
|
|
}
|
|
|
|
void myDoTRACE(LPCTSTR lpszFormat, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, lpszFormat);
|
|
|
|
CString s;
|
|
s.FormatV(lpszFormat, args);
|
|
|
|
OutputDebugString(s);
|
|
|
|
va_end(args);
|
|
}
|
|
|
|
const CString myGetLastErrorMsg()
|
|
{
|
|
LPSTR lpBuffer;
|
|
DWORD dwError = GetLastError();
|
|
int nResult = 0;
|
|
if (dwError >= 12000 && dwError <= 12174)
|
|
nResult = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
|
|
GetModuleHandle("wininet.dll"), dwError, 0,
|
|
(LPSTR)&lpBuffer, 0, NULL);
|
|
else
|
|
nResult = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
NULL, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
|
(LPSTR)&lpBuffer, 0, NULL);
|
|
if (nResult)
|
|
{
|
|
CString s(lpBuffer);
|
|
LocalFree(lpBuffer);
|
|
return s;
|
|
}
|
|
|
|
return "Could not format errormessage";
|
|
}
|
|
|
|
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);
|
|
}
|