How to change the font in the console program during the execution of the program on the "Luida Console". I use Code Blocks.

Closed due to the fact that the essence of the question is not clear to the participants of gbg , aleksandr barakin , Grundy , Vartlok , Mike 20 May '16 at 20:05

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Do you want to change the font in your IDE from your program? - Alexander Petrov
  • @Alexander Petrov no. During program execution, in the console window. - Taras
  • Then where is Code Blocks? And let the user choose the font in his console: who has bad eyesight - will put a bigger font, etc. - Alexander Petrov
  • @ Alexander Petrov on the condition of the task to change the font programmatically. In Visual Studio there is some kind of function, but I don’t know if Code Blocks is there - Taras
  • The function is not in the IDE, it is in the language! What is the function in VS? Give her name. - Alexander Petrov

1 answer 1

From the discussion in the chat it turned out that GCC is being used.

You can change the font in the Windows console using the SetCurrentConsoleFontEx function. It is in the library KERNEL32.DLL . You can connect it dynamically. In addition, we define the structure CONSOLE_FONT_INFOEX , which is necessary to set the font parameters.

 #include <iostream> #include <windows.h> typedef struct _CONSOLE_FONT_INFOEX { ULONG cbSize; DWORD nFont; COORD dwFontSize; UINT FontFamily; UINT FontWeight; WCHAR FaceName[LF_FACESIZE]; } CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX; typedef BOOL (WINAPI *SETCURRENTCONSOLEFONTEX)(HANDLE, BOOL, PCONSOLE_FONT_INFOEX); SETCURRENTCONSOLEFONTEX SetCurrentConsoleFontEx; int main() { HMODULE hmod = GetModuleHandle("KERNEL32.DLL"); SetCurrentConsoleFontEx = (SETCURRENTCONSOLEFONTEX)GetProcAddress(hmod, "SetCurrentConsoleFontEx"); if (!SetCurrentConsoleFontEx) { std::cout << "error" << std::endl; exit(1); } CONSOLE_FONT_INFOEX font; ZeroMemory(&font, sizeof(CONSOLE_FONT_INFOEX)); font.cbSize = sizeof(CONSOLE_FONT_INFOEX); wcscpy(font.FaceName, L"Lucida Console"); font.dwFontSize.X = 10; font.dwFontSize.Y = 16; if (!SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), false, &font)) { std::cout << "error" << std::endl; exit(2); } std::cout << "Hello world!"; return 0; }