Console font size command

As implied from the title, is there any system(""); commands to alter the font size whilst running the program?

Otherwise my console app will be difficult to read for some users.

I already manipulate the colour scheme with system("color xy");

Where x and y represent different colour codes. But is there a way to do the same sort of thing but increasing the actual font size instead?

Thank you for any help you can provide :)
I don't think this is possible with system(). You have to take a platform specific way.
On windows, see http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx
The one you need is SetCurrentConsoleFontEx.
Also, for colors you should use SetConsoleTextAttribute as it allows several different colors in different locations at the same time.
Thank you for the site but i do not understand how to call this particular function or the other one for colour settings?
You need a handle returned by GetStdHandle. example:
1
2
3
4
SetConsoleTextAttribute(
    GetStdHandle(STD_OUTPUT_HANDLE),
    0xFC
);


When you try changing font size, you should first get the CONSOLE_FONT_INFOEX structure with GetCurrentConsoleFontEx, change the size member and then call SetCurrentConsoleFontEx.
I am sorry but that didn't make much sense to me at all :S

I have not progressed into HANDLE's properly yet and have only touched on them whilst using them to set/get clipboard text.

When getting the CONSOLE_FONT_INFOEX structure what do I need to set it to?

Will the following be what I need?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//define a struct to hold the info
typedef struct console_info {
  ULONG cbSize;
  DWORD nFont;
  COORD dwFontSize;
  UINT  FontFamily;
  UINT  FontWeight;
  WCHAR FaceName[LF_FACESIZE];
} console_info;

//retrieve info
GetCurrentConsoleFontEx( GetStdHandle(STD_OUTPUT_HANDLE), false, console_info);

//adjust heights
console_info.dwFontSize.X = 9;
console_info.dwFontSize.Y = 9;

//set info
SetCurrentConsoleFontEx( GetStdHandle(STD_OUTPUT_HANDLE), false, console_info);
No. Are you unfamiliar with structs? If so, you may want to read this: http://www.cplusplus.com/doc/tutorial/structures/

here's a full example. I can't say if it works, because apparently functions Get/SerCurrentConsoleFontEx are only available in windows vista and later.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <windows.h>

int main(){
    HANDLE outcon = GetStdHandle(STD_OUTPUT_HANDLE);//you don't have to call this function every time

    CONSOLE_FONT_INFOEX font;//CONSOLE_FONT_INFOEX is defined in some windows header
    GetCurrentConsoleFontEx(outcon, false, &font);//PCONSOLE_FONT_INFOEX is the same as CONSOLE_FONT_INFOEX*
    font.dwFontSize.X = 7;
    font.dwFontSize.Y = 12;
    SetCurrentConsoleFontEx(outcon, false, &font);
    
    SetConsoleTextAttribute(outcon, 0x0C);
    std::cout << "I'm red";
    std::cin.get();
    return 0;
}
Err i touched upon ita while back just forgot it XD.

Im running vista but getting problems.


847 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `HANDLE' undeclared (first use this function)



848 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `CONSOLE_FONT_INFOEX' undeclared (first use this function)



849 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `GetCurrentConsoleFontEx' undeclared (first use this function)



852 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `SetCurrentConsoleFontEx' undeclared (first use this function)



853 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `SetConsoleTextAttribute' undeclared (first use this function)


possible header file not included?


EDIT: upon including the <Wincon.h> header file (as suggested by google), i get LOADS if errors similar to:


60 C:\Dev-Cpp\include\Wincon.h `WCHAR' does not name a type

186 C:\Dev-Cpp\include\Wincon.h `WINAPI' does not name a type



any ideas?
Last edited on
As in my example, #include <windows.h>
i missed that XD

Ok i done as you said and included that file too but although it has drastically reduced the problems there still remain a few:


850 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `CONSOLE_FONT_INFOEX' undeclared (first use this function)

851 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `GetCurrentConsoleFontEx' undeclared (first use this function)

854 C:\Users\Chazz & Bill\Documents\prog\exercises.tictactoe\main.cpp `SetCurrentConsoleFontEx' undeclared (first use this function)


in my program i included:

1
2
3
4
5
6
7
8
9
10
11
#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <Wincon.h>

// For time() and random
#include <ctime>    
#include <cstdlib> 
Last edited on
Is this yet more examples of people trying to do things with the console that they shouldn't be?

I do believe so!

=P
yes i know there are easier ways to do it with an app but i want a command line based prog atm :)

If it is possible i see no reason not to do so in this case as although it uses these calls in a roundabout way and uses alot more processing, the simple fact of the matter is in this program its not big enough to make a difference to be honest and i simply wish to learn :)
Topic archived. No new replies allowed.