| |
CONSOLE: howto change console font programmaticallyOne might think that changing console font (size, face, etc.) is as easy as changing regular window font. Actually it is not. Moreover I have found no way to change it once the console app is started. o Why do we need that ? Apart from the fact that one could just want to create an application that always uses his favourite font, KpyM Telnet Server really needs special font properties. Rather it needs special font size. The problem is that console window size is limited by the screen size. The higher your screen resolution is larger maximum console window size you get. You can easily imagine, a client running at 1280 x 1024 connecting to KTS host at 800x600. Using the same font size on both client and host the max client telnet window would be larger than the max KTS host console window. It generally means that the client window size is limited by host window size. The most annoying thing about that situation is that telnet window size negotiation works only in one direction, from client to host. The host has no legal way to tell client, "Hey, I can't stretch console anymore, please act accordingly". When KTS panics about client/host window size it would print a message saying "warning: host(80x71)/client(81x122) window size mismatch", no more no less. Although there is no complete solution to that problem, a partial solution is to use in host KTS console the smallest font size possible. Thus you get the same max console window size, but due to the smaller font size you get more rows and columns per same screen size. o The solution. When dealing with regular windows you have a bunch of useful font functions. Unfortunately they do not work on console windows. There is no "legal" way to manipulate console fonts once the application is started. Luckily you could do that before starting the app using few “hacks”. There are several ways: - default console settings. You can change the default console settings. These settings are written in the registry under the HKEY_CURRENT_USER\Console key. See that article for details. Unfortunately there is a major disadvantage; these settings affect all console windows and it is annoying to force the user to use console with font size of 5pts. - console settings for title It is a slightly modified variant of the previous. The difference is that you set the settings only for the console window with specified title. Of course you could hardly use that trick if you generate console title dynamically, the way KTS does. - using a shortcut Accidentally I happened to notice that console app shortcuts have a font tab. I was quite happy that I found no disadvantage using shortcuts for setting font size prior to launching the app. Shortcuts are easy to manipulate programmatically too, using the COM shell link interface. For additional information on using shell link you can look at that article o Conclusion. It seems windows console is quite overthrown by Microsoft. Although there are a bunch of Win API functions allowing console manipulation, and even there are few new console functions added in the recent SDKs, it still lacks quite a lot of useful functions. Unfortunately on of the missing ones is a function allowing font size manipulations. This results in using ugly hacks such as manipulating registry or using shortcuts to launch a console app with the desired font. Sunday, November 06, 2005
© 2002 - 2008 Kroum Grigorov
|