Jump to content
  • Advertisement
Sign in to follow this  

Console Font/Size

This topic is 4496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to lock the console size in my program so that the user cannot change any of the settings. I am doing this by resetting the size and font of the console on every loop. Problems: My Program pauses for Input. I am using cin to get input. This needs to stop, how should I get input? I know that storing the keystrokes to a buffer in realtime, the processing them per frame would be better. I have checked the MSDN and google, but I still can't figure this one out. I have no Idea how to set the font. I am using GetCurrentConsoleFont() to get the current font (I have no idea what the default font is... or I would just set it to that. GetCurrenTConsoleFont() doesn't seem to work. But I am including windows.h. I couldn't find a SetConsoleFont in the MSDN, so I am using SetConsoleFontEx instead. A few other compiler errors which I will adress, but I need this to work first. So, here is my working code. Thanks!
bool StringPump::SizeScreen(int height, int width, COORD font)
     SMALL_RECT rec;
     CONSOLE_FONT_INFO tempfont;
     tempfont.dwFontSize = font;
     tempfont.nFont = (GetCurrentConsoleFont()).nFont;
     rec.Top = 0;
     rec.Left = 0;
     rec.Right = font.X * width; // 80 chars wide
     rec.Bottom = font.Y * height; //32 chars high
     SetConsoleWindowInfo(CONS_HANDLE, false, &rec);
     SetCurrentConsoleFontEx(CONS_HANDLE, false, &tempfont);

and I shall include my error log, cause it will probably help you help me, and I am all for that.
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Austen\My Documents\projects\1\Makefile.win"
Executing  make clean
rm -f ../1/main.o ../1/StringPump.o ../1/item.o ../1/StateMan.o ../1/creatures.o ../1/Equipment.o ../1/Austens_Lil'_project_private.res "Austens Lil' project.exe"

g++.exe -D__DEBUG__ -c main.cpp -o ../1/main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"    -ansi -fexpensive-optimizations -g3

g++.exe -D__DEBUG__ -c StringPump.cpp -o ../1/StringPump.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"    -ansi -fexpensive-optimizations -g3

StringPump.cpp: In member function `bool StringPump::SizeScreen(int, int, COORD)':
StringPump.cpp:252: error: `GetCurrentConsoleFont' undeclared (first use this function)
StringPump.cpp:252: error: (Each undeclared identifier is reported only once for each function it appears in.)

StringPump.cpp:258: error: `SetCurrentConsoleFontEx' undeclared (first use this function)

make.exe: *** [../1/StringPump.o] Error 1

Execution terminated

I am using DEV-C++ 4.8 or 5. something. The latest one I think. Oh, here is teh Screen8032 struct
struct Screen8032 
       char buffer[32][80]; //32 lines, 80 chars per line
       int colors[32][80];

It is basically 2 2d arrays of chars and ints, one for color of character, one for character icon. Thanks for your help! [edit] the reason that I didn't just hardcode the size settings is so I can reuse it. For anything. I guess this is restating the obvious, but I think it might be slightly apropreate

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
You'll need to define _WIN32_WINNT as 0x500 or more in order to use these functions (before including Windows.h obviously).

Share this post

Link to post
Share on other sites
Thanks, but it didn't fix the problem. I added
#define _WIN32_WINNT 0x500


#include <windows.h>

in my header, but I get the same ( and more warnings) errors

#include <cstdlib>
#include <iostream>
#define _WIN32_WINNT 0x501
#include <windows.h>
#include <string>
#include <vector>
#include <queue>

Am I doing this wrong? Do the functions really exist?


Share this post

Link to post
Share on other sites
Works for me.

Do the functions really exist?

Look in the headers. You should find it in wincon.h. Since you don't know what compiler version you have it's possible that you have an old version of the Windows SDK. You should also move the #define up to the top. It's possible that cstdlib or something is already including windows.h and by the time you get around to changing the version it's to late.

I have to say though, I can't imagine any legitimate use for not allowing the user to change the console font. Why exactly do you care? I can easily imagine your app completely breaking in (say) Japanese locales which use a very different console font than English locales.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!