www.pudn.com > Gimcrack-v0.0051-Source.zip > dbgconsole.h
#ifndef _DBGCONSOLE_H_ #define _DBGCONSOLE_H_ #include#include //#define DEBUGMODE class GcDebugConsole { public: /*DebugConsole() { }*/ GcDebugConsole( char * title ) { #ifdef DEBUGMODE AllocConsole(); SetConsoleTitle(title); m_file = fopen("debug.txt", "w"); #endif } ~GcDebugConsole() { #ifdef DEBUGMODE FreeConsole(); if( m_file ) fclose(m_file); #endif } void Write( char * fmt, ... ) { #ifdef DEBUGMODE char s[300]; va_list argptr; //int cnt; //va_start(argptr, fmt); //cnt = s(s, fmt, argptr); //va_end(argptr); va_start(argptr, fmt); vsprintf(s, fmt, argptr); va_end(argptr); strcat(s, "\n"); DWORD CharsWritten; WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), s, strlen(s), &CharsWritten, NULL); if( m_file ) fprintf(m_file, s); #endif } void Clear() { #ifdef DEBUGMODE HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord = {0, 0}; DWORD count; CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(hStdOut, &csbi); FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count); SetConsoleCursorPosition(hStdOut, coord); #endif } void Move( int x, int y ) { #ifdef DEBUGMODE /*HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(handle, &info); info.srWindow.Left = 0; info.srWindow.Top = 0; info.srWindow.Right = 50; info.srWindow.Bottom = 50; SetConsoleWindowInfo(handle, true, &info.srWindow); /*RECT rc = {0, 0, width, height}; int centerX; int centerY; /* Adjust that to a size that includes the border, etc. ::AdjustWindowRectEx (&rc, WS_OVERLAPPEDWINDOW, ::GetMenu (m_hwnd) != NULL, 0); /* Extended style of the main window centerX = (::GetSystemMetrics (SM_CXFULLSCREEN) / 2) - (abs (rc.left) + rc.right) / 2; centerY = (::GetSystemMetrics (SM_CYFULLSCREEN) / 2) - (abs (rc.top) + rc.bottom) / 2; //centerX = width MoveWindow(m_hwnd, x, y, (rc.right - rc.left), (rc.bottom - rc.top), TRUE);*/ #endif } private: FILE * m_file; }; #endif