size the console window

closed account (28poGNh0)
Hey everyone
I am looking for a function or a maner that sizes the console window

thanks for reading
@Techno01

This should be what you're looking for.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Resize Console.cpp : main project file.

#include <conio.h> // For WaitKey() function
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
using namespace System;

void WaitKey();

int main()
{
	int x;
	const int width = 91, height = 60;
	Console::SetWindowSize(width, height );
	cout << "Making console, narrower!!" << endl;
	for(x=120;x>=width;x--)
	{
		
		Console::SetWindowSize(x, height);
		Sleep(200);
	}
	cout << "Making console, shorter!!" << endl;
	for(x=60;x>26;x--)
	{
		Console::SetWindowSize(width, x);
		Sleep(200);
	}
	WaitKey();
	return 0;
}

void WaitKey()
{
	cout << "\n\n\n\t\t\t     Press ENTER to continue...";
	while (_kbhit()) _getch(); // Empty the input buffer
	_getch(); // Wait for a key
	while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)
}
closed account (28poGNh0)
Thanks a lot @whitenite1

but It did not work for me
I am programming in block notes compiler is that a problem because it did not recongnize the "namespace System"
@Tecno01

Sorry, I have no idea what 'block notes compiler', is. I've heard of 'Code::Blocks', but I'm not sure if that is what you meant. In any case, I'm not not familiar with either one, to be able to give you a definitive answer.
I just threw this together, there are no guarantees that it is correct, or works at all:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define _WIN32_WINNT 0x0501
#include <conio.h>
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

    COORD a;
    a.X = 90;
    a.Y = 300;

    SMALL_RECT rect;
    rect.Top = 0;
    rect.Left = 0;
    rect.Bottom = 10;
    rect.Right = 30;


    SetConsoleScreenBufferSize(handle, a);

    SetConsoleWindowInfo(handle, 1, &rect);

    cout << "Making console bigger" << endl;

    for (int i=0; i< 20; i++)
    {
        rect.Bottom++;
        rect.Right++;
        int x = SetConsoleWindowInfo(handle, 1, &rect);
        if (x == 0)
        {
            cout <<  GetLastError() << endl;
        }
        // 6  - handle is invalid
        // 87 - invalid parameter

        Sleep(200);
    }

    getch();
    return 0;
}

Last edited on
closed account (28poGNh0)
@whitenite1
Oh my god I can't beleive I wrote that ,I meant Code::Blocks
but thanks anyway

for you @Chervil
thats what I'am looking for
a 100000 thks
Topic archived. No new replies allowed.