xLogWnd.h
资源名称:MM.zip [点击查看]
上传用户:jyxwjx
上传日期:2020-03-13
资源大小:221k
文件大小:6k
源码类别:
多显示器编程
开发平台:
Visual C++
- // xLogWnd.h: interface for the xLogWnd class.
- //
- //////////////////////////////////////////////////////////////////////
- #pragma once
- // [xLogWnd Handling Document at 20040528 by numsealsoft]
- //
- // 肺弊酒眶阑 荤侩窍妨搁 促澜阑 曼炼窍绞矫坷
- // 肺弊酒眶狼 蜡屈篮 技啊瘤涝聪促.
- //
- // 1) 老馆肺弊 : 老馆利牢 格利栏肺 荤侩邓聪促.
- // 2) 版绊肺弊 : 版绊己 格利栏肺 荤侩邓聪促.
- // 3) 俊矾肺弊 : 俊矾惯积矫 荤侩邓聪促.
- //
- // 促澜苞 鞍篮 规过栏肺 荤侩窍绞矫坷.
- // A) XLOGOUT:老馆肺弊
- // Ex1: XLOGOUT(_T("printf狼 屈侥栏肺 器杆泼窍绞矫坷."));
- // Ex2: XLOGOUT(_T("%04d : 老馆肺弊涝聪促."), 100);
- //
- // B) XLOGWAR:版绊肺弊
- // Ex1: XLOGWAR(_T("%04d : 版绊肺弊涝聪促."), 100);
- //
- // C) XLOGERR:俊矾肺弊
- // Ex1: XLOGERR(_T("%04d : 俊矾肺弊涝聪促."), 100);
- //
- // 磊技茄 肺弊酒眶阑 困茄 待橇甫 瘤盔钦聪促.
- // Prepare Ex)
- // TCHAR pDump[2048];
- // ::lstrcpy(pDump, _T("捞巴篮 待橇单捞磐涝聪促."), 10);
- //
- // A) XDUMPOUT:老馆肺弊
- // Ex1: XDUMPOUT(pDump)(_T("%04d : 老馆肺弊涝聪促."), 100);
- //
- // B) XDUMPWAR:版绊肺弊
- // Ex1: XDUMPWAR(pDump)(_T("%04d : 版绊肺弊涝聪促."), 100);
- //
- // C) XDUMPERR:老馆肺弊
- // Ex1: XDUMPERR(pDump)(_T("%04d : 俊矾肺弊涝聪促."), 100);
- //
- // 歹宽 磊技茄 肺弊酒眶阑 瘤盔钦聪促.
- // GetLastError()狼 皋矫瘤绰 待橇邓聪促.
- //
- // A) XLOGOUT_LASTERROR : GetLastError()甫 器杆泼钦聪促.
- // Ex1:
- // try {
- // ... some error
- // } catch (...) {
- // XLOGOUT_LASTERROR;
- // }
- //
- //
- static LPCTSTR g_logOut = _T("xLogWnd");
- static LPCTSTR g_logOutwindowClassName = _T("xLogWnd Receiver");
- // iType
- #define XLIT_ADVANCE 0
- #define XLIT_WARNING 1
- #define XLIT_ERROR 2
- // Buffer Limitation
- #define _MAX_FROM 1024
- #define _MAX_WHERE 1024
- #define _MAX_MESSAGE 2048
- #define _MAX_DUMP 2048
- typedef struct _XLOGITEM {
- int iType;
- TCHAR pszFrom[_MAX_FROM];
- TCHAR pszWhere[_MAX_WHERE];
- TCHAR pszMessage[_MAX_MESSAGE];
- TCHAR pszDump[_MAX_DUMP];
- } XLOGITEM, FAR* LPXLOGITEM;
- inline void _LogOut (int nType, LPCTSTR pFrom, LPCTSTR pWhere, LPCTSTR pMessage, LPCTSTR pDump)
- {
- COPYDATASTRUCT cd;
- HWND hWnd = ::FindWindow (g_logOutwindowClassName, g_logOut);
- if (hWnd)
- {
- XLOGITEM li;
- ::memset(&li, NULL, sizeof(XLOGITEM));
- li.iType = nType;
- if (pFrom)
- {
- #ifdef _UNICODE
- ::lstrcpynW(li.pszFrom, pFrom, _MAX_FROM);
- #else
- ::lstrcpyn(li.pszFrom, pFrom, _MAX_FROM);
- #endif
- }
- if (pWhere)
- {
- #ifdef _UNICODE
- ::lstrcpynW(li.pszWhere, pWhere, _MAX_WHERE);
- #else
- ::lstrcpyn(li.pszWhere, pWhere, _MAX_WHERE);
- #endif
- }
- if (pMessage)
- {
- #ifdef _UNICODE
- ::lstrcpynW(li.pszMessage, pMessage, _MAX_MESSAGE);
- #else
- ::lstrcpyn(li.pszMessage, pMessage, _MAX_MESSAGE);
- #endif
- }
- if (pDump)
- {
- #ifdef _UNICODE
- ::lstrcpynW(li.pszDump, pDump, _MAX_DUMP);
- #else
- ::lstrcpyn(li.pszDump, pDump, _MAX_DUMP);
- #endif
- }
- #ifdef _UNICODE
- cd.dwData = 0xFEFF;
- #else
- cd.dwData = 0;
- #endif
- cd.cbData = sizeof(XLOGITEM);
- cd.lpData = (void *)&li;
- ::SendMessage (hWnd, WM_COPYDATA, 0, (LPARAM)&cd);
- }
- }
- inline LPCTSTR LogFormat (LPCTSTR pFormat, ...)
- {
- va_list args;
- va_start(args, pFormat);
- static _TCHAR buffer[2048] = {0,};
- wvsprintf(buffer, pFormat, args);
- va_end(args);
- return buffer;
- }
- inline void LogOut (int iType, void* pFilename, unsigned int lineno, LPCTSTR pszMessage, LPCTSTR pDump = NULL)
- {
- TCHAR where[_MAX_WHERE] = {0,};
- TCHAR Filename[_MAX_WHERE] = {0,};
- #ifdef _UNICODE
- MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pFilename, (int)strlen((LPCSTR)pFilename)+1, Filename, (int)sizeof(Filename)/sizeof(Filename[0]) );
- #else
- ::lstrcpyn(Filename, (LPTSTR)pFilename, _MAX_WHERE);
- #endif
- wsprintf(where, _T("%d line in %s"), lineno, (LPTSTR)Filename);
- _LogOut (iType, ::AfxGetAppName(), where, pszMessage, pDump);
- }
- inline DWORD LogOutLastError (void* pFilename, unsigned int lineno, LPCTSTR pszMessage)
- {
- if (::GetLastError() == 0)
- return 0;
- LPVOID pDump;
- DWORD result;
- result = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPTSTR)&pDump,
- 0,
- NULL);
- ::LogOut(XLIT_ERROR, pFilename, lineno, pszMessage, (LPCTSTR)pDump);
- if(result)
- ::LocalFree(pDump);
- return result;
- }
- class CxLogSystem {
- public:
- CxLogSystem(int nType, void* pFrom, int nLineno, LPCTSTR pDump = NULL)
- : m_pFrom(pFrom), m_nLineno(nLineno), m_nType(nType), m_pDump(pDump), m_nLastError(0)
- {
- }
- CxLogSystem(int nType, void* pFrom, int nLineno, int nLastError)
- : m_pFrom(pFrom), m_nLineno(nLineno), m_nType(nType),
- m_pDump(NULL), m_nLastError(nLastError)
- {
- }
- inline void Trace(LPCTSTR pFormat, ...)
- {
- va_list args;
- va_start(args, pFormat);
- static _TCHAR buffer[2048] = {0,};
- wvsprintf(buffer, pFormat, args);
- va_end(args);
- LogOut(m_nType, m_pFrom, m_nLineno, buffer, m_pDump);
- }
- inline void TraceLastError()
- {
- if (m_nLastError == 0)
- return;
- static _TCHAR buffer[2048] = {0,};
- wsprintf(buffer, _T(" %d : the calling thread's last-error code value"), m_nLastError);
- LPVOID pDump;
- DWORD result;
- result = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- m_nLastError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPTSTR)&pDump,
- 0,
- NULL);
- ::LogOut(XLIT_ERROR, m_pFrom, m_nLineno, buffer, (LPCTSTR)pDump);
- if(result)
- ::LocalFree(pDump);
- }
- protected:
- int m_nLastError;
- int m_nType;
- int m_nLineno;
- void* m_pFrom;
- LPCTSTR m_pDump;
- };
- // XLOGOUT
- #define XLOGFMT ::LogFormat
- #define XLOGOUT CxLogSystem(XLIT_ADVANCE, __FILE__, __LINE__).Trace
- #define XLOGWAR CxLogSystem(XLIT_WARNING, __FILE__, __LINE__).Trace
- #define XLOGERR CxLogSystem(XLIT_ERROR, __FILE__, __LINE__).Trace
- #define XDUMPOUT(dump) CxLogSystem(XLIT_ADVANCE, __FILE__, __LINE__, dump).Trace
- #define XDUMPWAR(dump) CxLogSystem(XLIT_WARNING, __FILE__, __LINE__, dump).Trace
- #define XDUMPERR(dump) CxLogSystem(XLIT_ERROR, __FILE__, __LINE__, dump).Trace
- // XLOGOUT_LASTERROR
- #define XLOGOUT_LASTERROR CxLogSystem(XLIT_ERROR, __FILE__, __LINE__, GetLastError()).TraceLastError()