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