question

KeithLovell-4623 avatar image
0 Votes"
KeithLovell-4623 asked ·

Console window size in c++ for VS19.

I am developing a c++ console application and would like to increase the size of the default console window that is produced by c++ under vs19. If it is possible, how would that be achieved?

c++vs-setup
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered ·

It's a little more involved than you might expect.
Start by reading this thread:

Console: how change window size?
https://social.msdn.microsoft.com/Forums/en-US/0de248af-3497-4537-bb41-6d129b04fb27/console-how-change-window-size

  • Wayne

· 9 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have included what I think is the end result of the thread and am getting a whole lot of undefined identifiers. Is there something that I have to #include to make it work? My current #includes are:

include <iostream>

include <iomanip>

include <string>

include <cstdlib>

include <cstdio>

include <random>

include <vector>

include <fstream>


Keith

0 Votes 0 ·

Do you have this one?


 #include <windows.h>

  • Wayne

0 Votes 0 ·

When you work with the Windows API functions you should take the time to read the documentation. Some of the essential pieces of information that the docs provide are the headers, library and dll associated with the function. For example, code in the referenced thread makes use of the GetConsoleScreenBufferInfoEx Function. The docs include this -
24159-docs.png


0 Votes 0 ·
docs.png (20.2 KiB)

Thanks Wayne. That has worked except that the position of the console on the screen seems to be a bit random as I change the size parameters..

I take your comment about reading the documentation on board. I find the documentation is OK if you know what you are looking for but not very useful if you are trying to find out how to do something with no real idea of what the process will be. I guess I will get more fluent with it in time.

Right now I am trying to find out how to change the console to black text on a white background. As near as I can tell, the approach is to fill the buffer with characters (spaces) that have the attribute of black text on a white background. Is there a more elegant way to do it as it seems to me that the foreground and background defaults would be a property of the console rather than each of the individual characters??

Keith

0 Votes 0 ·
Show more comments
AnnaXiu-MSFT avatar image
0 Votes"
AnnaXiu-MSFT answered ·

Hi KeithLovell,

Please view the similar issue and have a try with the following steps:
1. Right-click on the title bar of Console Window;
2. Select Properties;
3. Navigate to Layout;
4. Set the Window Size and click on OK;

If there is something wrong, please feel free to contact us.

Best regards,
Anna






· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I actually wanted to do it in the program. :-) I will try to follow the thread tagged above but it is a bit confusing! :-)

0 Votes 0 ·
RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered ·

Give this a try to change the console colors -

  #include <Windows.h>
  #include <stdio.h>
    
  int main() {
  CONSOLE_SCREEN_BUFFER_INFOEX csbi{ sizeof csbi };
    
  HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    
  GetConsoleScreenBufferInfoEx(hOutput, &csbi);
    
  csbi.wAttributes = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
    
  SetConsoleScreenBufferInfoEx(hOutput, &csbi);
    
  printf("Text to Console\n");
    
  return 0;
  }


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.