DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/debug/debug_win32.cpp
00001 /*
00002  *  Copyright (C) 2002-2013  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifdef WIN32
00020 
00021 #include <windows.h>
00022 #include <stdio.h>
00023 #include <stdarg.h>
00024 
00025 #ifndef min
00026 #define min(a,b) ((a)<(b)?(a):(b))
00027 #endif
00028 
00029 /* 
00030         Have to remember where i ripped this code sometime ago.
00031 
00032 */
00033 static void ResizeConsole( HANDLE hConsole, SHORT xSize, SHORT ySize ) {   
00034         CONSOLE_SCREEN_BUFFER_INFO csbi; // Hold Current Console Buffer Info 
00035         BOOL bSuccess;   
00036         SMALL_RECT srWindowRect;         // Hold the New Console Size 
00037         COORD coordScreen;    
00038         
00039         bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
00040         
00041         // Get the Largest Size we can size the Console Window to 
00042         coordScreen = GetLargestConsoleWindowSize( hConsole );
00043         
00044         // Define the New Console Window Size and Scroll Position 
00045         srWindowRect.Right  = (SHORT)(min(xSize, coordScreen.X) - 1);
00046         srWindowRect.Bottom = (SHORT)(min(ySize, coordScreen.Y) - 1);
00047         srWindowRect.Left   = srWindowRect.Top = (SHORT)0;
00048         
00049         // Define the New Console Buffer Size    
00050         coordScreen.X = xSize;
00051         coordScreen.Y = ySize;
00052         
00053         // If the Current Buffer is Larger than what we want, Resize the 
00054         // Console Window First, then the Buffer 
00055         if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize)
00056         {
00057                 bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
00058                 bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
00059         }
00060         
00061         // If the Current Buffer is Smaller than what we want, Resize the 
00062         // Buffer First, then the Console Window 
00063         if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize )
00064         {
00065                 bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
00066                 bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
00067         }
00068         
00069         // If the Current Buffer *is* the Size we want, Don't do anything! 
00070     (void)bSuccess;//UNUSED
00071         return;
00072    }
00073 
00074 
00075 void WIN32_Console() {
00076         AllocConsole();
00077         SetConsoleTitle("DOSBox Debugger");
00078         ResizeConsole(GetStdHandle(STD_OUTPUT_HANDLE),80,50);
00079 }
00080 #endif