console.h
来自「finite element mesh 参数化有限元网格划分」· C头文件 代码 · 共 155 行
H
155 行
/* Author: Dhandy */
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
// uncomment the line below to get the console in release version also.
//#define _RELEASE_CONSOLE_
#ifdef _DEBUG
#define WANT_DEBUG_CONSOLE
#else
#ifdef _RELEASE_CONSOLE_
#define WANT_DEBUG_CONSOLE
#endif
#endif
#ifdef WANT_DEBUG_CONSOLE
#define CreateConsole() { AllocConsole(); }
#define DeleteConsole() { FreeConsole(); }
#define cout(val) _cout(_T("")_T(#val), val)
#else
#define CreateConsole()
#define DeleteConsole()
#define cout(val)
#define _cout
#endif
#ifdef WANT_DEBUG_CONSOLE
inline CString GetLastErrorText(BOOL bShowMessageBoxAlso = TRUE)
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );
CString cstrMessageText = (LPTSTR)lpMsgBuf;
if(bShowMessageBoxAlso == TRUE)
{
// Display the string.
MessageBox( NULL, cstrMessageText, _T("GetLastErrorText"), MB_OK|MB_ICONINFORMATION );
}
// Free the buffer.
LocalFree( lpMsgBuf );
return cstrMessageText;
}
inline void _cout(CString dummy, CString string)
{
DWORD dwBytes;
if(dummy.Find(_T('"')) == -1)
{
dummy += _T(" = ");
}
else
{
dummy = "";
}
CString cstrBuf = dummy;
cstrBuf += string + _T('\n');
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(char ch)
{
DWORD dwBytes;
CString cstrBuf = " ";
cstrBuf.SetAt(0, ch);
cstrBuf += _T('\n');
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(unsigned char ch)
{
DWORD dwBytes;
CString cstrBuf = " ";
cstrBuf.SetAt(0,ch);
cstrBuf += _T('\n');
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, int n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %d\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, unsigned int n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %d\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, float n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %f\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, double n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %g\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, long n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %u\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
inline void _cout(CString cstr, unsigned long n)
{
DWORD dwBytes;
CString cstrBuf;
cstrBuf.Format(_T(" = %u\n"), n);
cstr += cstrBuf;
cstrBuf = cstr;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), (LPCTSTR)cstrBuf, cstrBuf.GetLength() + 1, &dwBytes, NULL);
}
#endif // WANT_DEBUG_CONSOLE
#endif // _CONSOLE_H_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?