In a std I/O application, output occurs to the current console. The font used for outputting text into the associated window is controlled by the system and can be changed via the console properties.
The following function can be used to determine the size of the font set for the window associated with the current console. This information can be used for calculating the space that will be occupied by a text block send to the console, for example.
Simply call this function in your std I/O to get the size of the console font. Example:
The following function can be used to determine the size of the font set for the window associated with the current console. This information can be used for calculating the space that will be occupied by a text block send to the console, for example.
Xbase++:
#include "dll.ch"
#include "fileio.ch"
#include "xbp.ch"
/*
BOOL WINAPI GetCurrentConsoleFont(
_In_ HANDLE hConsoleOutput,
_In_ BOOL bMaximumWindow,
_Out_ PCONSOLE_FONT_INFO lpConsoleCurrentFont );
*/
EXTERN BOOL GetCurrentConsoleFont( hCon AS UINTEGER, bMaxWindow AS BOOL, @CurrFont AS STRUCTURE) IN WIN32API
/*
HANDLE WINAPI GetStdHandle(
_In_ DWORD nStdHandle );
*/
EXTERN UINTEGER GetStdHandle( nStdHandle AS INTEGER ) IN WIN32API
STRUCTURE COORD
VAR x AS SHORT
VAR y AS SHORT
ENDSTRUCTURE
STRUCTURE CONSOLE_FONT_INFO
VAR nFont AS UINTEGER
VAR dwFontSize AS STRUCTURE COORD
ENDSTRUCTURE
//////////////////////////////////////////////////////////////////////
/// <summary>
/// Determine size of the font used by the window associated with the
/// current console
/// </summary>
/// <returns>
/// An array of the form {<nWidth>,<nHeight>} with the pixel width
/// and height of the font, respectively. In case of an error, return
/// is {0,0}
/// </returns>
//////////////////////////////////////////////////////////////////////
FUNCTION GetConsoleFontSize()
LOCAL nCon
LOCAL oFI AS STRUCTURE CONSOLE_FONT_INFO
LOCAL aRet := {0,0}
IF AppType() != APPTYPE_VIO
RETURN aRet
ENDIF
// determine standard out handle of OS
nCon := GetStdHandle( FH_STDOUT )
// query font info for output handle
IF GetCurrentConsoleFont(nCon, .F., @oFI)
aRet := {oFI:dwFontSize:x, oFI:dwFontSize:y}
ENDIF
RETURN aRet
Simply call this function in your std I/O to get the size of the console font. Example:
Xbase++:
#include "simpleio.ch"
PROCEDURE Main()
? "Height of the console font:", GetConsoleFontSize()[2]
RETURN
PROCEDURE AppSys()
// Prevent creation of the default application window
RETURN