define window size

Hello! I program in C + + ah few months and develop application in console mode and which function in the code would set the size of the application window?

researched some on the internet and tested them, but does not work
which one is correct?

Use Dev C + + compiler 4.9.9.2
Last edited on
closed account (zb0S216C)
brunopescarolli wrote:
which function in the code would set the size of the application window?

Non of the standard libraries support the following:

- Audio
- Video
- Graphics
- Artificial Intelligence
- User Interface Elements

In order for you to do what you're asking, you'd have to pull in your OS's API and call the appropriate functions. Of course, since you've been programming for a couple of months, it's likely that the OS's API will confuse you. It's best to stick with the default size, rather than dive into a unknown territory head first.

brunopescarolli wrote:
Use Dev C + + compiler

...is not a compiler. Dev-C++ uses an old version of MinGW's compiler suite. It's best to update you IDE to Code::Blocks, or Visual C++ Express (the free version).

Wazzak
I used the following function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h>
//função em C++ de configurar tamanho da janela personalizada ".h"

//configWindown.h

void configtela()//função q configura o tamanho da tela e do buffer
{
COORD outbuff;
outbuff.X = 50; // tem que ser 1 maior que o tamanho X
outbuff.Y = 70; // tem que ser 1 maior que o tamanho Y
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleScreenBufferSize(hConsole, outbuff);
Sleep(130);
SMALL_RECT windowSize = {0, 0, 900, 70}; 
SetConsoleWindowInfo(hConsole, TRUE, &windowSize);
}


I tried but does not work, actually do not know how he uses it
I put the file name of "configWindow.h" and then I include in the project thus: #include "configWindow.h"

I did something wrong?, I use Windows Xp
Last edited on
closed account (zb0S216C)
brunopescarolli wrote:
actually do not know how he uses it

Which means you don't understand what you're reading. Just how much of C++ do you know?

brunopescarolli wrote:
I put the file name of "configWindow.h" and then I include in the project

Did "configWindow.h" come with the project?

Wazzak
I am beginner guy ok?

"configWindow.h" I that I created! which has the code I posted above after initially includes the project in order to adjust the window size

@brunopescarolli

Here is a small program I had written, which has a larger console window. I added in a fo loop to shrink it before the program ends. By studying this, you should be able to use the concept in your program as well. Good luck..

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// LCD Numbers.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
using namespace System;

void WaitKey();

int main()
{
	int t,x;
	const int width = 91, height = 60;
	Console::SetWindowSize(width, height ); // Adjust values of width and height, to desired dimensions needed  
	string Segment[2][11][10]={
		{{" \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
		{"\x1E     \x1E","      \x1E","      \x1E","      \x1E","\x1E     \x1E","\x1E      ","\x1E      ","      \x1E","\x1E     \x1E","\x1E     \x1E"},
		{"\xDB     \xDB","      \xDB","      \xDB","      \xDB","\xDB     \xDB","\xDB      ","\xDB      ","      \xDB","\xDB     \xDB","\xDB     \xDB"},
		{"\xDB     \xDB","      \xDB","      \xDB","      \xDB","\xDB     \xDB","\xDB      ","\xDB      ","      \xDB","\xDB     \xDB","\xDB     \xDB"},
		{"\x1F     \x1F","      \x1F","      \x1F","      \x1F","\x1F     \x1F","\x1F      ","\x1F      ","      \x1F","\x1F     \x1F","\x1F     \x1F"},
		{"       ","       ", " \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
		{"\x1E     \x1E","      \x1E","\x1E      ","      \x1E","      \x1E","      \x1E","\x1E     \x1E","      \x1E","\x1E     \x1E","      \x1E"},
		{"\xDB     \xDB","      \xDB","\xDB      ","      \xDB","      \xDB","      \xDB","\xDB     \xDB","      \xDB","\xDB     \xDB","      \xDB"},
		{"\xDB     \xDB","      \xDB","\xDB      ","      \xDB","      \xDB","      \xDB","\xDB     \xDB","      \xDB","\xDB     \xDB","      \xDB"},
		{"\x1F     \x1F","      \x1F","\x1F      ","      \x1F","      \x1F","      \x1F","\x1F     \x1F","      \x1F","\x1F     \x1F","      \x1F"},
		{" \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 ","       "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "}
		},
		{{" \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "},
		{"\xF8     \xF8","      \xF8","      \xF8","      \xF8","\xF8     \xF8","\xF8      ","\xF8      ","      \xF8","\xF8     \xF8","\xF8     \xF8"},
		{"\xF8     \xF8","      \xF8","      \xF8","      \xF8","\xF8     \xF8","\xF8      ","\xF8      ","      \xF8","\xF8     \xF8","\xF8     \xF8"},
		{"\xF8     \xF8","      \xF8","      \xF8","      \xF8","\xF8     \xF8","\xF8      ","\xF8      ","      \xF8","\xF8     \xF8","\xF8     \xF8"},
		{"\xF8     \xF8","      \xF8","      \xF8","      \xF8","\xF8     \xF8","\xF8      ","\xF8      ","      \xF8","\xF8     \xF8","\xF8     \xF8"},
		{"       ","       ", " \xF8\xF8\xF8\xF8\xF8 ","   \xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "},
		{"\xF8     \xF8","      \xF8","\xF8      ","      \xF8","      \xF8","      \xF8","\xF8     \xF8","      \xF8","\xF8     \xF8","      \xF8"},
		{"\xF8     \xF8","      \xF8","\xF8      ","      \xF8","      \xF8","      \xF8","\xF8     \xF8","      \xF8","\xF8     \xF8","      \xF8"},
		{"\xF8     \xF8","      \xF8","\xF8      ","      \xF8","      \xF8","      \xF8","\xF8     \xF8","      \xF8","\xF8     \xF8","      \xF8"},
		{"\xF8     \xF8","      \xF8","\xF8      ","      \xF8","      \xF8","      \xF8","\xF8     \xF8","      \xF8","\xF8     \xF8","      \xF8"},
		{" \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 ","       "," \xF8\xF8\xF8\xF8\xF8 "," \xF8\xF8\xF8\xF8\xF8 "}
		}		
	};

		string Colon[2][11] = {
			{"       ","       ","   \x1E   ","   \x1F   ","       ","       ","       ","   \x1E   ","   \x1F   ","       ","       "},
			{"       ","       ","       ",   "   \xF8   ","       ","       ","       ","   \xF8   ","       ",   "       ","       "}
		};

		cout << endl << endl;
		for (x=0;x<2;x++)
		{
			for(t=0;t<11;t++)
			{
				cout <<  "   " << Segment[x][t][0] << " " << Segment[x][t][1] << 
" " << Segment[x][t][2] << " " << Segment[x][t][3] << " " << Segment[x][t][4] << 
" " << Segment[x][t][5] << " " << Segment[x][t][6] << " " << Segment[x][t][7] <<
 " " << Segment[x][t][8] << " " << Segment[x][t][9] << " " << Colon[x][t] << endl;
			}
			cout << endl;
		}
		for(x = height;x>height-33;x--)
		{
			Console::SetWindowSize(width, x );
			Sleep(100);
		}

		WaitKey();

		return 0;
}


void WaitKey()
{
	cout << "\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)
}
@brunopescarolli:

(I know you're a beginner, so just read the bottom paragraph here if all of this goes totally over your head)

The window size can never be larger than the console screen buffer size or the max window size.

In your function, you're most likely trying to set the window size beyond both the screen buffer size and the max window size. (window length of 900 character cells?!)
That's why it's failing.

If you're not familiar with messing with this stuff, don't bother trying to set the window size...
...you won't need to in a majority of cases, anyways.
Last edited on
Topic archived. No new replies allowed.