How to get spacing between characters printed using TextOut ?
- by life-warrior
I'm trying to calcuate size of each cell (containing text like "ff" or "a0"), so that 32 cells will fit into window by width.
However, charWidth*2 doesn' represent the width of a cell, since it doesn't take spacing between characters in the account.
How can I obtain size of a font so that 32 cells each is two chars like "ff" fit exactly into window's client area ?
Curier is fixed-width font.
RECT rect;
::GetClientRect( hWnd, &rect );
LONG charWidth = (rect.right-rect.left)/BLOCK_SIZE/2-2;
int oldMapMode = ::SetMapMode( hdc, MM_TEXT );
HFONT font = CreateFont( charWidth*2, charWidth, 0, 0, FW_DONTCARE, FALSE,
FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, FF_ROMAN, _T("Courier") );
HGDIOBJ oldFont = ::SelectObject( hdc, font );
for( int i = 0; i < BLOCK_SIZE; ++i )
{
CString str;
str.Format( _T("%.2x"), (unsigned char)*(g_memAddr+i) );
SIZE size;
::TextOut( hdc, (size.cx+2)*i+1, 1, str, _tcslen((LPCTSTR)str) );
}