Skip to content

Instantly share code, notes, and snippets.

@Vladimir-Novick
Last active March 20, 2022 08:34
Show Gist options
  • Save Vladimir-Novick/9a8ad206aaa32a484bb2b61098d92054 to your computer and use it in GitHub Desktop.
Save Vladimir-Novick/9a8ad206aaa32a484bb2b61098d92054 to your computer and use it in GitHub Desktop.
POINT CDefaultAppFont::GetFontSize(CFont* pFont,CHAR *str)
{
POINT p = { 0 };
auto mainWindow = AfxGetApp()->GetMainWnd();
if (mainWindow != NULL) {
auto hDC = GetWindowDC(mainWindow->m_hWnd);
CDC* pDC = CDC::FromHandle(hDC);
CFont* pOldFont = pDC->SelectObject(pFont);
SIZE sizeText;
if (str == NULL) {
GetTextExtentPoint32(pDC->m_hDC, "Z", 1, &sizeText);
}
else {
GetTextExtentPoint32(pDC->m_hDC, str, strlen(str), &sizeText);
}
pDC->SelectObject(pOldFont);
p.y = sizeText.cy;
p.x = sizeText.cx;
}
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment