此方法是以磅为单位的字号
int CRichEditDlg::GetCharFormatHeigh( int nFontSize )
{
CDC *pDC = GetDC();
HDC hDC = pDC->GetSafeHdc();
int lfHeight=MulDiv(nFontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(pDC);
return -lfHeight*15;
}
lfHeight是否需要添加负号,请根据需要参照MSDN上的LOGFONT说明。
另外附上通过lfHeight获取对应字号的方法:
int CRichEditDlg::GetFontSize(int height)
{
CDC *pDC = GetDC();
HDC hDC = pDC->GetSafeHdc();
int nFontSize = -MulDiv(height/15, 72, GetDeviceCaps(hDC, LOGPIXELSY));
ReleaseDC(pDC);
return nFontSize;
}