15,979
社区成员
发帖
与我相关
我的任务
分享
void CSuperStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawStatic( &dc );
}
void CMyStatic::DrawStatic( CDC *pDC )
{
CString strText;
GetWindowText( strText );
if ( strText.GetLength() == 0 )
return;
CRect rect;
GetClientRect( &rect );
DWORD dwStyle = GetStyle();
dwStyle |= DT_SINGLELINE | DT_VCENTER;
CFont *pOldFont = NULL;
// 目的是使字段和控件的高度相匹配,占用高度的7/8
CFont *pFont = GetFont();
LOGFONT stuLogFont;
pFont->GetLogFont( &stuLogFont );
double f = rect.Height() * 7 / 8 * 1.0 / stuLogFont.lfHeight;
stuLogFont.lfHeight = long(stuLogFont.lfHeight * f);
CFont fnt;
fnt.CreateFontIndirect( &stuLogFont );
pOldFont = pDC->SelectObject( &fnt ); // 只要这里设置了,内容就会前后颠倒,否则就是正常的
pDC->SetBkMode( TRANSPARENT );
if ( (dwStyle & DT_CENTER) != DT_CENTER )
rect.left += 3;
pDC->DrawText( strText, &rect, dwStyle );
if ( pOldFont )
pDC->SelectObject( pOldFont );
}
DWORD dwStyle = pDC->GetTextAlign();
DWORD dw1 = GetStyle()&0xFF;
dwStyle |= DT_SINGLELINE | DT_VCENTER | dw1;
GetClientRect( &rect );
DWORD dwStyle = GetStyle();
dwStyle |= DT_SINGLELINE | DT_VCENTER;
GetClientRect( &rect );
DWORD dwStyle = pDC->GetTextAlign();
dwStyle |= DT_SINGLELINE | DT_VCENTER;