Is there any way to get the width of a string in pixels without using CDC or using a CDC not linked with a display. The class that needs to retrieve the string width does not inherit from CWnd in order to use CWnd::GetDC() and there is no way to pass an existing CDC to the function.
I have tried to create a dummy CDC that is not linked with a display, however this causes MFC to crash. Ideally something like:
m_font = new CFont();
m_font->CreatePointFont(size * 10, _T("Arial"));
m_tempCDC = new CDC();
m_tempCDC->SelectObject(m_font);
return m_tempCDC->GetOutputTextExtent(_T("Test")).cx;
EDIT: Should have substituted the font name variable for a string literal.