////////////////////////////////////旋转字体 void CViewFontView::OnDraw(CDC* pDC) { CViewFontDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CString str(_T("Visua C++6.0编程实例"));//定义要显示的字符串; CRect rect; GetClientRect(&rect); pDC->SetBkMode(TRANSPARENT);//设置背景为透明效果; pDC->SetTextColor(RGB(100,100,255));//设置显示的文本颜色; CFont font; LOGFONT stFont;//定义字体结构; memset(&stFont,0,sizeof(stFont));//设置字体结构的属性; stFont.lfHeight=30; stFont.lfWeight=FW_NORMAL; stFont.lfClipPrecision=CLIP_LH_ANGLES; strcpy(stFont.lfFaceName,"Arial"); //下面的代码以视图中心为圆点,在半径100的圆周上每隔30度显示字符串; for(double i=0;i<3600;i+=300) { stFont.lfEscapement=i;//设置字体的倾斜角度; font.CreateFontIndirect(&stFont);//根据字体结构创建字体对象; CFont *oldFont; oldFont=pDC->SelectObject(&font);//将创建的字体选入设备上下文; if(i<900) pDC->TextOut(rect.left+rect.Width )/2+100*cos(i/1800*3.14),rect.top+rect.Height ()/2-100*sin(i/1800*3.14),str); if(i>=900&&i<1800) pDC->TextOut(rect.left+rect.Width ()/2+100*cos(i/1800*3.14), rect.top+rect.Height ()/2-100*sin(i/1800*3.14),str); if(i>=1800&&i<2700) pDC->TextOut(rect.left+rect.Width ()/2+100*cos(i/1800*3.14), rect.top+rect.Height ()/2-100*sin(i/1800*3.14),str); if(i>=2700&&i<=3600) pDC->TextOut(rect.left+rect.Width ()/2+100*cos(i/1800*3.14), rect.top+rect.Height ()/2-100*sin(i/1800*3.14),str); pDC->SelectObject(oldFont);//恢复设备上下文的字体; font.DeleteObject ();//删除创建的字体; } } //////////////////////////////////////////显示3D效果的程序 void CMy3DTextView::OnDraw(CDC* pDC) { CMy3DTextDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CString string; string="Visual C++6.0编程实例"; CFont m_fontLogo; m_fontLogo.CreateFont(144, 0, 0, 0, 155, FALSE, FALSE,0,0,0,0,0,0, "Arial"); //创建字体; pDC->SetBkMode(TRANSPARENT); CRect rectText; GetClientRect(&rectText); CFont * OldFont = pDC->SelectObject(&m_fontLogo); COLORREF OldColor = pDC->SetTextColor( ::GetSysColor( COLOR_3DSHADOW)); //阴影状态显示文字; pDC->DrawText( string, rectText+CPoint(2,2) , DT_SINGLELINE | DT_LEFT |DT_VCENTER|DT_CENTER); pDC->SetTextColor(::GetSysColor( COLOR_3DHILIGHT) ); //高亮状态显示文字; pDC->DrawText( string, rectText, DT_SINGLELINE | DT_LEFT |DT_VCENTER|DT_CENTER); pDC->SetTextColor( OldColor); pDC->SelectObject(OldFont); m_fontLogo.DeleteObject(); } |