|
|
1.1 root 1: #include <windows.h>
2: #include "console.h"
3:
1.1.1.2 ! root 4: /* Microsoft Developer Support
! 5: Copyright (c) 1992 Microsoft Corporation */
! 6:
1.1 root 7: /*********************************************************************
8: * FUNCTION: resizeConBufAndWindow(HANDLE hConsole, SHORT xSize, *
9: * SHORT ySize) *
10: * *
11: * PURPOSE: resize both the console output buffer and the console *
12: * window to the given x and y size parameters *
13: * *
14: * INPUT: the console output handle to resize, and the required x and *
15: * y size to resize the buffer and window to. *
16: * *
17: * COMMENTS: Note that care must be taken to resize the correct item *
18: * first; you cannot have a console buffer that is smaller *
19: * than the console window. *
20: *********************************************************************/
21:
22: static void resizeConBufAndWindow(HANDLE hConsole, SHORT xSize, SHORT ySize)
23: {
24: CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */
25: BOOL bSuccess;
26: SMALL_RECT srWindowRect; /* hold the new console size */
27: COORD coordScreen;
28:
29: setConTitle(__FILE__);
30: bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
31: PERR(bSuccess, "GetConsoleScreenBufferInfo");
32: /* define the new console size */
33: srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
34: srWindowRect.Right = (SHORT) (xSize - 1);
35: srWindowRect.Bottom = (SHORT) (ySize - 1);
36: /* define the new console buffer size */
37: coordScreen.X = xSize;
38: coordScreen.Y = ySize;
39: /* if the current buffer is larger than what we want, resize the */
40: /* console window first, then the buffer */
41: if (csbi.dwSize.X * csbi.dwSize.Y > xSize * ySize)
42: {
43: bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
44: PERR(bSuccess, "SetConsoleWindowInfo");
45: bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
46: PERR(bSuccess, "SetConsoleScreenBufferSize");
47: }
48: /* if the current buffer is smaller than what we want, resize the */
49: /* buffer first, then the console window */
50: if (csbi.dwSize.X * csbi.dwSize.Y < xSize * ySize)
51: {
52: bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
53: PERR(bSuccess, "SetConsoleScreenBufferSize");
54: bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
55: PERR(bSuccess, "SetConsoleWindowInfo");
56: }
57: return;
58: }
59:
60:
61: /*********************************************************************
62: * FUNCTION: demoSizeInfo(HANDLE hConOut) *
63: * *
64: * PURPOSE: demonstrate SetConsoleWindowInfo and *
65: * SetConsoleScreenBufferSize. Resize the console buffer and *
66: * window *
67: * *
68: * INPUT: console output handle to set the information for *
69: *********************************************************************/
70:
71: void demoSizeInfo(HANDLE hConOut)
72: {
73: SHORT sConX, sConY; /* save the current console dimensions */
74:
75: myPuts(hConOut, "Let's resize the console buffer and window to a 40 x 25");
76: myPuts(hConOut, "size screen by using the SetConsoleScreenBufferSize and");
77: myPuts(hConOut, "SetConsoleWindowInfo APIs. Hit enter to continue...");
78: myGetchar();
79: sConX = getConX(hConOut);
80: sConY = getConY(hConOut);
81: resizeConBufAndWindow(hConOut, (SHORT) 40, (SHORT) 25);
82: myPuts(hConOut, "Now let's resize back to our original");
83: myPuts(hConOut, "size screen.");
84: myPuts(hConOut, "Hit enter to continue...");
85: myGetchar();
86: resizeConBufAndWindow(hConOut, sConX, sConY);
87: myPuts(hConOut, "Now we're back to our original size. Hit enter to return...");
88: myGetchar();
89: return;
90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.