c++ change console font size

i want change console font size, i try codes from internet but not work

add latest test
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
#include<windows.h>
#include <iostream>
using namespace std;
int testFont[2];
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
void setFontSize(int a,int b)
{
     testFont[0] = a;
	 testFont[1] = b;
	 SetCurrentConsoleFontEx(hConsole, TRUE, testFont);
}
   void size_convertor(int sk=0){

    switch(sk){
    case 1:
        setFontSize(2,2);
        break;
    case 2:
        setFontSize(4,4);
        break;
    case 3:
        setFontSize(6,6);
        break;
    case 4:
        setFontSize(8,8);
        break;
    default:
        setFontSize(6,12);
        break;
    }
Answer: Don’t do that.

Font size is the user’s purview. Not the program’s.

If you want specialized font stuff, create your own window and select a font into the GDC and draw with that.

OR, create a shortcut for your program and set the font with that.

Sorry it isn’t the answer you wanted.
The problem is, the only connection between the console is a data stream of what text goes into and out of the console. The console is a separate program that is the mouth piece of you program. The issue comes when different operating systems/flavors use different consoles. There is no common "settings" channel between your program and the console program, only the text streams.

--Edit--

I forgot to mention there is a "common language" that most consoles use (excluding windows because they are special). These are ANSI escape code, which can be used to change color and cursor position. I usually don't like referencing Wikipedia but this page is very good starting point. These codes are sent over the data stream already established.

https://en.wikipedia.org/wiki/ANSI_escape_code
Last edited on
If you are going to do modal programming with the console, use NCurses on *nixen and the Windows API + windows VT escape sequences on Windows. (This is what “most” programs will do.)
i get this error using http://www.cplusplus.com/forum/general/118967/ code
||=== Build: Debug in film (compiler: GNU GCC Compiler) ===|
D:\c++woėr\film\draw.h|10|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11|
D:\c++woėr\film\draw.h|11|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11|
D:\c++woėr\film\draw.h|13|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11|
D:\c++woėr\film\draw.h||In function 'void setFontSize(int)':|
D:\c++woėr\film\draw.h|18|error: 'CONSOLE_FONT_INFOEX' was not declared in this scope|
D:\c++woėr\film\draw.h|19|error: 'info' was not declared in this scope|
D:\c++woėr\film\draw.h|23|error: 'SetCurrentConsoleFontEx' was not declared in this scope|
D:\c++woėr\film\draw.h||In function 'void gotoxy(int, int)':|
D:\c++woėr\film\draw.h|51|warning: narrowing conversion of 'xa' from 'int' to 'SHORT {aka short int}' inside { } is ill-formed in C++11 [-Wnarrowing]|
D:\c++woėr\film\draw.h|51|warning: narrowing conversion of 'ya' from 'int' to 'SHORT {aka short int}' inside { } is ill-formed in C++11 [-Wnarrowing]|
D:\c++woėr\film\draw.h|69|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11|
||=== Build failed: 3 error(s), 6 warning(s) (0 minute(s), 0 second(s)) ===|

You need to include windows.h and the User32 library.
how import User32 library,
i using codeblock
I already did it https://c-for-dummies.com/blog/?p=2159 but not work
Topic archived. No new replies allowed.