|
|
1.1.1.3 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: #include <windows.h> 13: #include "console.h" 14: 15: /********************************************************************* 16: * FUNCTION: resizeConBufAndWindow(HANDLE hConsole, SHORT xSize, * 17: * SHORT ySize) * 18: * * 19: * PURPOSE: resize both the console output buffer and the console * 20: * window to the given x and y size parameters * 21: * * 22: * INPUT: the console output handle to resize, and the required x and * 23: * y size to resize the buffer and window to. * 24: * * 25: * COMMENTS: Note that care must be taken to resize the correct item * 26: * first; you cannot have a console buffer that is smaller * 27: * than the console window. * 28: *********************************************************************/ 29: 1.1.1.3 ! root 30: void resizeConBufAndWindow(HANDLE hConsole, SHORT xSize, SHORT ySize) 1.1 root 31: { 32: CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ 33: BOOL bSuccess; 34: SMALL_RECT srWindowRect; /* hold the new console size */ 35: COORD coordScreen; 36: 37: bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); 38: PERR(bSuccess, "GetConsoleScreenBufferInfo"); 1.1.1.3 ! root 39: /* get the largest size we can size the console window to */ ! 40: coordScreen = GetLargestConsoleWindowSize(hConsole); ! 41: PERR(coordScreen.X | coordScreen.Y, "GetLargestConsoleWindowSize"); ! 42: /* define the new console window size and scroll position */ ! 43: srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); ! 44: srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); 1.1 root 45: srWindowRect.Left = srWindowRect.Top = (SHORT) 0; 46: /* define the new console buffer size */ 47: coordScreen.X = xSize; 48: coordScreen.Y = ySize; 49: /* if the current buffer is larger than what we want, resize the */ 50: /* console window first, then the buffer */ 1.1.1.3 ! root 51: if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize) 1.1 root 52: { 53: bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); 54: PERR(bSuccess, "SetConsoleWindowInfo"); 55: bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); 56: PERR(bSuccess, "SetConsoleScreenBufferSize"); 57: } 58: /* if the current buffer is smaller than what we want, resize the */ 59: /* buffer first, then the console window */ 1.1.1.3 ! root 60: if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize) 1.1 root 61: { 62: bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); 63: PERR(bSuccess, "SetConsoleScreenBufferSize"); 64: bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); 65: PERR(bSuccess, "SetConsoleWindowInfo"); 66: } 1.1.1.3 ! root 67: /* if the current buffer *is* the size we want, don't do anything! */ 1.1 root 68: return; 69: } 70: 71: 72: /********************************************************************* 73: * FUNCTION: demoSizeInfo(HANDLE hConOut) * 74: * * 75: * PURPOSE: demonstrate SetConsoleWindowInfo and * 76: * SetConsoleScreenBufferSize. Resize the console buffer and * 77: * window * 78: * * 79: * INPUT: console output handle to set the information for * 80: *********************************************************************/ 81: 82: void demoSizeInfo(HANDLE hConOut) 83: { 84: SHORT sConX, sConY; /* save the current console dimensions */ 85: 1.1.1.3 ! root 86: setConTitle(__FILE__); ! 87: myPuts(hConOut, "Let's resize the console buffer and window to a 40 x 25\n" ! 88: "size screen by using the SetConsoleScreenBufferSize and\n" ! 89: "SetConsoleWindowInfo APIs. Hit enter to continue...\n"); 1.1 root 90: myGetchar(); 91: sConX = getConX(hConOut); 92: sConY = getConY(hConOut); 93: resizeConBufAndWindow(hConOut, (SHORT) 40, (SHORT) 25); 1.1.1.3 ! root 94: myPuts(hConOut, "Now let's resize to a large size of\n" ! 95: "200 x 200 - notice that the console\n" ! 96: "window size will not grow larger than\n" ! 97: "the physical screen size. Hit enter\n" ! 98: "to continue...\n"); ! 99: myGetchar(); ! 100: resizeConBufAndWindow(hConOut, (SHORT) 200, (SHORT) 200); ! 101: myPuts(hConOut, "Now let's resize back to our original size screen.\n" ! 102: "Hit enter to continue...\n"); 1.1 root 103: myGetchar(); 104: resizeConBufAndWindow(hConOut, sConX, sConY); 105: myPuts(hConOut, "Now we're back to our original size. Hit enter to return..."); 106: myGetchar(); 107: return; 108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.