uint32_t WIN_FONT::GetTextWidth(const char* theText, uint32_t theLength)
// Return the number of pixels width the text is base on the font info.
{
uint32_t width = 0;
wchar_t* wcString = NULL;
int32_t wcLength = CreateWideString(theText, theLength, &wcString);
if (wcLength > 0)
{
HDC hdc = GetDC(NULL);
(HFONT)SelectObject(hdc, (HGDIOBJ)winFont);
SIZE size;
if(GetTextExtentPoint32W(hdc, wcString, wcLength, &size))
{
width = size.cx;
}
ReleaseDC(NULL, hdc); // <= Error detected here
delete[] wcString;
}
return width;
}
Recent Comments