Back to index

lightning-sunbird  0.9+nobinonly
guicon.cpp
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 
00003 //#include <windows.h>
00004 #include <stdio.h>
00005 #include <fcntl.h>
00006 
00007 #include <io.h>
00008 
00009 //#include <iostream>
00010 
00011 //#include <fstream>
00012 
00013 //#ifndef _USE_OLD_IOSTREAMS
00014 //using namespace std;
00015 //#endif
00016 
00017 // maximum mumber of lines the output console should have
00018 
00019 static const WORD MAX_CONSOLE_LINES = 500;
00020 
00021 
00022 
00023 #ifdef _DEBUG
00024 
00025 
00026 void RedirectIOToConsole()
00027 
00028 {
00029 
00030 int hConHandle;
00031 
00032 long lStdHandle;
00033 
00034 CONSOLE_SCREEN_BUFFER_INFO coninfo;
00035 
00036 FILE *fp;
00037 
00038 // allocate a console for this app
00039 
00040 AllocConsole();
00041 
00042 // set the screen buffer to be big enough to let us scroll text
00043 
00044 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
00045 
00046 coninfo.dwSize.Y = MAX_CONSOLE_LINES;
00047 
00048 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
00049 
00050 // redirect unbuffered STDOUT to the console
00051 
00052 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
00053 
00054 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00055 
00056 fp = _fdopen( hConHandle, "w" );
00057 
00058 *stdout = *fp;
00059 
00060 setvbuf( stdout, NULL, _IONBF, 0 );
00061 
00062 // redirect unbuffered STDIN to the console
00063 
00064 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
00065 
00066 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00067 
00068 fp = _fdopen( hConHandle, "r" );
00069 
00070 *stdin = *fp;
00071 
00072 setvbuf( stdin, NULL, _IONBF, 0 );
00073 
00074 // redirect unbuffered STDERR to the console
00075 
00076 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
00077 
00078 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00079 
00080 fp = _fdopen( hConHandle, "w" );
00081 
00082 *stderr = *fp;
00083 
00084 setvbuf( stderr, NULL, _IONBF, 0 );
00085 
00086 
00087 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
00088 // point to console as well
00089 
00090 //ios::sync_with_stdio();
00091 
00092 }
00093 
00094 #endif
00095 
00096 //End of File
00097