1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
LRESULT CMyStatic::OnSetText(UINT wParam, LONG lParam)
{
LPCTSTR lpsz;
lpsz=(LPCTSTR)lParam;
CRect Rect;
LOGFONT lf;
GetClientRect(&Rect);
if(!m_Font.m_hObject) // m_font c'est l'objet CFontEx de la faq
{
m_Font.GetFont(8,"Arial");
SetFont(&m_Font,FALSE);
}
CClientDC dc(this);
m_Font.GetLogFont(&lf); // Get Current font properties
do
{
SIZE sz;
::GetTextExtentPoint32(dc.GetSafeHdc(), lpsz, strlen(lpsz), &sz);
if( sz.cx > Rect.Width())
{
if(lf.lfHeight<0) lf.lfHeight ++; // diminue font size
else lf.lfHeight --; // diminue font size
m_Font.DeleteObject();
m_Font.CreateFontIndirect(&lf);
dc.SelectObject(&m_Font);
continue;
}
break;
}
while(1);
SetFont( &m_Font,FALSE);
return Default();
} |
Partager