The console uses "fixed width fonts"
, such as "Courier New"
(available in all Windows version) or "Consolas"
(available since Vista).
Fixed width fonts are not necessarily raster. To use raster fonts, enumerate fonts to find a raster font such as "Terminal"
or "Fixedsys"
. You have to use the right size (example, 18 for "Terminal"
font) otherwise Windows may substitute a different font and resize. There are also issues with DPI settings. If program is not DPI aware then magnification will occur if work station has high DPI settings.
case WM_PAINT:
{
PAINTSTRUCT ps;
auto hdc = BeginPaint(hwnd, &ps);
auto hfont = CreateFont(-18, 0, 0, 0, 0, 0, 0, 0,
ANSI_CHARSET,
OUT_DEVICE_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
L"Terminal");
auto oldfont = SelectObject(hdc, hfont);
RECT rc = { 0,0,100,300 };
DrawText(hdc, L"Test 123", -1, &rc, DT_LEFT | DT_TOP);
SelectObject(hdc, oldfont);
DeleteObject(hfont);
EndPaint(hwnd, &ps);
return 0;
}