📄 solarassert.cpp
字号:
#include "UtilityCommon.h"
#include "SolarAssert.h"
#include <string>
#pragma warning( disable:4786 )
const char * _pszAssertCaption = "Solar Assert";
const char * _pszIgnoreCaption = "Ask to Ignore Message";
const char * _pszCoypyRight = "Copyright (c) SUN Studio & Webzen.Ltd..";
const char * _pszIgnoreMessage = "捞 瘤痢狼 AssertMessageBox甫 促澜俊档 角青窍矫摆嚼聪鳖?";
UINT _uiAssertMessageBoxType = MB_SETFOREGROUND | MB_APPLMODAL | MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION;
UINT _uiIgnoreMessageBoxType = MB_YESNO | MB_DEFBUTTON2;
char _pszVarDescription[512];
static int (APIENTRY * _pfnMessageBoxA)(HWND, LPCSTR, LPCSTR, UINT) = NULL;
static HWND (APIENTRY * _pfnGetActiveWindow)(void) = NULL;
static HWND (APIENTRY * _pfnGetLastActivePopup)(HWND) = NULL;
void _copy2Clipboard( const char * msg )
{
if( OpenClipboard( NULL ) )
{
HGLOBAL hMem = NULL;
char * pMem = 0;
hMem = GlobalAlloc( GHND | GMEM_DDESHARE, strlen( msg ) + 1 );
if( pMem )
{
pMem = (char *)GlobalLock( hMem );
strcpy( pMem, msg );
GlobalUnlock( hMem );
EmptyClipboard();
SetClipboardData( CF_TEXT, hMem );
}
CloseClipboard();
}
}
int _crtMessageBox( LPCSTR lpMsg, LPCSTR lpCaption, UINT uiType )
{
HWND hwnd = NULL;
if( NULL == _pfnMessageBoxA )
{
HANDLE hLib = LoadLibrary( "user32.dll" );
if( NULL == hLib || NULL == ( _pfnMessageBoxA = (int (APIENTRY *)(HWND, LPCSTR, LPCSTR, UINT))GetProcAddress( (HMODULE)hLib, "MessageBoxA" ) ) )
return 0;
_pfnGetActiveWindow = (HWND (APIENTRY *)(void))GetProcAddress( (HMODULE)hLib, "GetActiveWindow" ) ;
_pfnGetLastActivePopup = (HWND (APIENTRY *)(HWND))GetProcAddress( (HMODULE)hLib, "GetLastActivePopup" ) ;
}
if( _pfnGetActiveWindow )
hwnd = (*_pfnGetActiveWindow)();
if( hwnd != NULL && _pfnGetLastActivePopup )
hwnd = (*_pfnGetLastActivePopup)(hwnd);
return (*_pfnMessageBoxA)( hwnd, lpMsg, lpCaption, uiType);
}
int _ignoreMessageBox()
{
return _crtMessageBox( _pszIgnoreMessage, _pszIgnoreMessage, _uiIgnoreMessageBoxType );
}
int _solarAssertBox( const char * pszDesc, int line, char * file, char * date, char * time )
{
char tmpLineNum[16];
std::string strMsgBuf;
strMsgBuf.append( "File : " );
strMsgBuf.append( file );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "Line # : " );
strMsgBuf.append( itoa(line, tmpLineNum, 10) );
strMsgBuf.append( " line\r\n" );
strMsgBuf.append( "Description : " );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "DateTime : " );
strMsgBuf.append( date );
strMsgBuf.append( " " );
strMsgBuf.append( time );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "-----------------------------------------------------------------------" );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( pszDesc );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "\r\n" );
_copy2Clipboard( strMsgBuf.c_str() );
strMsgBuf.append( "-----------------------------------------------------------------------" );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( "[吝窜(A)] 甫 穿福搁 橇肺弊伐阑 吝窜钦聪促.\r\n" );
strMsgBuf.append( "[促矫矫档(R)]甫 穿福搁 Assert 瘤痢栏肺 捞悼钦聪促.\r\n" );
strMsgBuf.append( "[公矫(I)] 甫 穿福搁 橇肺弊伐阑 拌加 柳青钦聪促.\r\n" );
strMsgBuf.append( "-----------------------------------------------------------------------" );
strMsgBuf.append( "\r\n" );
strMsgBuf.append( _pszCoypyRight );
strMsgBuf.append( "\r\n" );
int rt = _crtMessageBox( strMsgBuf.c_str(), _pszAssertCaption, _uiAssertMessageBoxType );
if( rt == IDABORT )
{
exit(9);// return 1;
}
if( rt == IDRETRY )
{
return 2;
}
if( rt == IDIGNORE )
{
return 3;
}
return 0;
}
char * VSTR( char * s, ...)
{
va_list arg;
va_start( arg, s );
vsprintf( _pszVarDescription, s, arg );
va_end( arg );
return _pszVarDescription;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -