I package this feature into two files, download this text to the local, saved to the correct file name. Implementing the source code without changing the source code, the debug version displays the debug information window, and does not realize the window in the Release version and does not increase the contractual burden.
############## DBWINDOW.H ######################
/ ************************************************** ******************* creation date: 2004/08/30 file name: DBWindow.h author: Liu Lei (vietor) version: 2.0 E-mail: liuleilover@163.com
Creating a target: Usually the DEBUG version needs to output the test information through the console, while compiling the code to the RELEASE version, it needs to be annotated, and these codes are more troublesome. The role of this program is that the debug version can be debugged in a separate console window when the MFC / DLL software development is performed, and does not have to manually comment on the Release version, which is automatically carry out. Note: Only one console window is present within a process, for multiple DLLs that may simultaneously debug, use color identification. Copyright Notice: You can copy and use the copy of this program at will, but please ensure that all files are complete and not modified, if you have a modified opinion, please contact the author. *********************************************************** ****************** /
#ifndef _dbwindow_ # define _dbwindow_
#include
// text color when the console output #define WDS_T_RED FOREGROUND_RED # define WDS_T_GREEN FOREGROUND_GREEN # define WDS_T_BLUE FOREGROUND_BLUE // background color of the text console output #define WDS_BG_RED BACKGROUND_RED # define WDS_BG_GREEN BACKGROUND_GREEN # define WDS_BG_BLUE BACKGROUND_BLUE
#ifdef _Debug
// Set the console output window title Bool DBWindOWTILE (LPCTSTR TILE); // Format the text Output Bool DBWindowWrite (LPCTSTR FMT, ...); // With color formatted text Output Bool DBWindowWrite (Word Attrs, LPCTSTR FMT ,. ..);
#ELSE
#define dbwindowtile # Define DBWindowWrite
#ENDIF
#ENDIF
############## DBWINDOW.CPP ################
/ ************************************************** ******************* creation date: 2004/08/30 file name: DBWindow.cpp author: Liu Lei (vietor) version: 2.0 E-mail: liuleilover@163.com
Creating a target: Usually the DEBUG version needs to output the test information through the console, while compiling the code to the RELEASE version, it needs to be annotated, and these codes are more troublesome. The role of this program is that the debug version can be debugged in a separate console window when the MFC / DLL software development is performed, and does not have to manually comment on the Release version, which is automatically carry out. Note: Only one console window is present within a process, for multiple DLLs that may simultaneously debug, use color identification. Copyright Notice: You can copy and use the copy of this program at will, but please ensure that all files are complete and not modified, if you have a modified opinion, please contact the author. *********************************************************** ***************************** / # include "stdafx.h" #include "dbwindow.h" #ifdef _debug # include "stdio.h"
#include "tchar.h"
#include "stdarg.h"
#define CONSOLE_TILE _T ( "DBWindow Ver 2.0 by LiuLei") class ConsoleWindow {public: ConsoleWindow (); virtual ~ ConsoleWindow (); BOOL SetTile (LPCTSTR lpTile); BOOL WriteString (LPCTSTR lpString); BOOL WriteString (WORD Attrs, LPCTSTR lpString ); private: HANDLE m_hConsole; BOOL m_bCreate; BOOL m_bAttrs; WORD m_OldColorAttrs;}; ConsoleWindow :: ConsoleWindow () {m_hConsole = NULL; m_bCreate = FALSE; if (AllocConsole ()) {m_hConsole = GetStdHandle (STD_OUTPUT_HANDLE); SetConsoleTitle (CONSOLE_TILE ); SetConsoleMode (m_hConsole, ENABLE_PROCESSED_OUTPUT); m_bCreate = TRUE;} else {m_hConsole = GetStdHandle (STD_OUTPUT_HANDLE); if (m_hConsole == INVALID_HANDLE_VALUE) m_hConsole = NULL;} if (m_hConsole) {CONSOLE_SCREEN_BUFFER_INFO csbiInfo; if (GetConsoleScreenBufferInfo (m_hConsole, & csbiInfo )) {m_bAttrs = TRUE; m_OldColorAttrs = csbiInfo.wAttributes;} else {m_bAttrs = FALSE; m_OldColorAttrs = 0;}}} ConsoleWindow :: ~ ConsoleWindow () {if (m_bCreate) FreeConsole ();} BOOL ConsoleWindow :: SetTile (LPCTSTR lpTile) {return SetConsoleTitle (lpTile);} BOOL ConsoleWindow :: WriteString (LPCTSTR lpString) {BOOL ret = FALSE; if (m_hConsole) {ret = WriteConsole (m_hConsole, lpString, _tcslen (lpString), NULL, NULL) ;} return ret;} BOOL ConsoleWindow :: WriteString (WORD Attrs, LPCTSTR lpString) {BOOL ret = FALSE; if (m_hConsole) {if (m_bAttrs) SetConsoleTextAttribute (m_hConsole, Attrs); ret = WriteConsole (m_hConsole, lpString, _tcslen ( lpString), NULL, NULL); if (m_bAttrs) SetConsoleTextAttribute (m_hConsole, m_OldColorAttrs);} return ret;} ConsoleWindow ConWindow; #define MAX_BUF_LEN 4096BOOL DBWindowTile (LPCTSTR tile) {return ConWindow.SetTile (tile);