-
August 19th, 2013, 11:17 AM
#1
[RESOLVED] about console size
the console have 2 types of size, right?
i belive that is the window size and the container size. the window size i can do it, but how can i change the container(i think that you call it buffer or something) size?
-
August 19th, 2013, 11:53 AM
#2
Re: about console size
There are 2 sizes associated with a console. The size of the window and the size of the buffer. The buffer can be greater than the size of the window, but the window cannot be greater than the buffer. Basically you write to the buffer and the window displays that portion of the buffer over which it is placed.
To set buffer size, use SetConsoleScreenBufferSize(...)
To get buffer size, use something like
Code:
DWORD GetBufferSize(HANDLE sout, COORD& size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
size.X = info.dwSize.X;
size.Y = info.dwSize.Y;
return (0);
}
To get windows size, you need something like this
Code:
DWORD GetConsoleSize(HANDLE sout, COORD& size)
{
CONSOLE_FONT_INFO cfinfo;
COORD fsize;
WINDOWINFO winfo;
if (!GetCurrentConsoleFont(sout, FALSE, &cfinfo)) {
return (GetLastError());
}
fsize = GetConsoleFontSize(sout, cfinfo.nFont);
if (!fsize.X && !fsize.Y) {
return (GetLastError());
}
winfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(GetConsoleWindow(), &winfo)) {
return (GetLastError());
}
size.Y = (SHORT)((winfo.rcClient.bottom - winfo.rcClient.top) / fsize.Y);
size.X = (SHORT)((winfo.rcClient.right - winfo.rcClient.left) / fsize.X);
return (0);
}
To set window size use something like this
Code:
DWORD SetConSize(HANDLE sout, COORD size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
info.srWindow.Top = 0;
info.srWindow.Bottom = size.Y - 1;
info.srWindow.Left = 0;
info.srWindow.Right = size.X - 1;
return (!SetConsoleWindowInfo(sout, TRUE, &info.srWindow) ? GetLastError() : 0);
}
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 19th, 2013, 11:56 AM
#3
Re: about console size
Originally Posted by 2kaud
There are 2 sizes associated with a console. The size of the window and the size of the buffer. The buffer can be greater than the size of the window, but the window cannot be greater than the buffer. Basically you write to the buffer and the window displays that portion of the buffer over which it is placed.
To set buffer size, use SetConsoleScreenBufferSize(...)
To get buffer size, use something like
Code:
DWORD GetBufferSize(HANDLE sout, COORD& size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
size.X = info.dwSize.X;
size.Y = info.dwSize.Y;
return (0);
}
To get windows size, you need something like this
Code:
DWORD GetConsoleSize(HANDLE sout, COORD& size)
{
CONSOLE_FONT_INFO cfinfo;
COORD fsize;
WINDOWINFO winfo;
if (!GetCurrentConsoleFont(sout, FALSE, &cfinfo)) {
return (GetLastError());
}
fsize = GetConsoleFontSize(sout, cfinfo.nFont);
if (!fsize.X && !fsize.Y) {
return (GetLastError());
}
winfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(GetConsoleWindow(), &winfo)) {
return (GetLastError());
}
size.Y = (SHORT)((winfo.rcClient.bottom - winfo.rcClient.top) / fsize.Y);
size.X = (SHORT)((winfo.rcClient.right - winfo.rcClient.left) / fsize.X);
return (0);
}
To set window size use something like this
Code:
DWORD SetConSize(HANDLE sout, COORD size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
info.srWindow.Top = 0;
info.srWindow.Bottom = size.Y - 1;
info.srWindow.Left = 0;
info.srWindow.Right = size.X - 1;
return (!SetConsoleWindowInfo(sout, TRUE, &info.srWindow) ? GetLastError() : 0);
}
i have 1 question:
"The buffer can be greater than the size of the window, but the window cannot be greater than the buffer."
is that why the vertical scrollbar is showed?
-
August 19th, 2013, 12:07 PM
#4
Re: about console size
Originally Posted by Cambalinho
i have 1 question:
"The buffer can be greater than the size of the window, but the window cannot be greater than the buffer."
is that why the vertical scrollbar is showed?
Yes, the window just shows a part of the buffer if the size of the buffer is greater than the size of the window. Depending upon how the sizes of the buffer and window have been set, you can get a horizontal scrollbar as well. If you don't want scroll bars then set the window size and the buffer size to be the same.
Note when setting buffer sizes that the rules apply! You cannot set a window greater than the buffer size and then set the buffer! The buffer needs to be set first and then the window size. Also if you are reducing the buffer size to be less than the current window size, then reduce the window size first and then the buffer size.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 19th, 2013, 12:39 PM
#5
Re: about console size
why the scrollbar isn't hided?
Code:
CONSOLE_SCREEN_BUFFER_INFO info;
RECT WindowRect;
GetWindowRect(ConsoleHandle,&WindowRect);
info.srWindow.Top =WindowRect.top;
info.srWindow.Left= WindowRect.left;
info.srWindow.Bottom = WindowRect.bottom;
info.srWindow.Right = WindowRect.right ;
SetConsoleWindowInfo(ConsoleDC, TRUE, &info.srWindow);
seems that these code is ignored
-
August 19th, 2013, 01:59 PM
#6
Re: about console size
What does this GetWindowRect return? TRUE or FALSE?
The same question - about GetWindowRect.
Victor Nijegorodov
-
August 19th, 2013, 02:08 PM
#7
Re: about console size
Originally Posted by VictorN
What does this GetWindowRect return? TRUE or FALSE?
The same question - about GetWindowRect.
the GetWindowRect() gives 1(true), the SetConsoleWindowInfo() gives me 0(false)
-
August 19th, 2013, 02:18 PM
#8
Re: about console size
Originally Posted by Cambalinho
why the scrollbar isn't hided?
Code:
CONSOLE_SCREEN_BUFFER_INFO info;
RECT WindowRect;
GetWindowRect(ConsoleHandle,&WindowRect);
info.srWindow.Top =WindowRect.top;
info.srWindow.Left= WindowRect.left;
info.srWindow.Bottom = WindowRect.bottom;
info.srWindow.Right = WindowRect.right ;
SetConsoleWindowInfo(ConsoleDC, TRUE, &info.srWindow);
seems that these code is ignored
What are you trying to accomplish? You're getting the size of the console window then you try to set the size and position of the console window to what it is already??
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 19th, 2013, 02:20 PM
#9
Re: about console size
Originally Posted by 2kaud
What are you trying to accomplish? You're getting the size of the console window then you try to set the size and position of the console window to what it is already??
buffer size = window size
-
August 19th, 2013, 02:30 PM
#10
Re: about console size
Originally Posted by Cambalinho
buffer size = window size
Then using the functions from above,
Code:
COORD consize;
GetConsoleSize(consoleDC, consize);
SetConsoleScreenBufferSize(consoleDC, consize);
Note you should test for errors.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 19th, 2013, 02:40 PM
#11
Re: about console size
Originally Posted by 2kaud
Then using the functions from above,
Code:
COORD consize;
GetConsoleSize(consoleDC, consize);
SetConsoleScreenBufferSize(consoleDC, consize);
Note you should test for errors.
sorry i don't have GetConsoleSize() what dll or library is need?
-
August 19th, 2013, 02:43 PM
#12
Re: about console size
Originally Posted by Cambalinho
the GetWindowRect() gives 1(true), the SetConsoleWindowInfo() gives me 0(false)
Then how about the call of GetLastError to obtain the extended error info?
Victor Nijegorodov
-
August 19th, 2013, 02:44 PM
#13
Re: about console size
sorry about that.. you shared. but if the windows and buffer sizes are the same, why the scrollbar stills there?
-
August 19th, 2013, 02:45 PM
#14
Re: about console size
Originally Posted by VictorN
Then how about the call of GetLastError to obtain the extended error info?
number 6.
-
August 19th, 2013, 02:56 PM
#15
Re: about console size
Originally Posted by Cambalinho
sorry i don't have GetConsoleSize() what dll or library is need?
I gave you the code for this in post #2.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|