gdi、gdi+计算输出文字的长度

gdi+

StringFormat strFormat;
    GraphicsPath path;
    FontFamily fontfamily;
    font.GetFamily(&fontfamily);
    path.AddString(outText.c_str(),-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat);
    RectF rcBound;
    path.GetBounds(&rcBound);

    int textWidth = rcBound.Width;



gdi

RECT rcRet = { 0 };
    HFONT hOldFont = (HFONT)::SelectObject(hdc,hFont);
    ::DrawText(hdc, strText, (int)_tcslen(strText), &rcRet, DT_LEFT | DT_CALCRECT);
    ::SelectObject(hdc, hOldFont);

    return rcRet;

你可能感兴趣的:(gdi、gdi+计算输出文字的长度)