www.pudn.com > 旋转文字和移动头像―卡通效果.zip > main.cpp
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "main.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; char text[] = "Hello"; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { fontangle = 0; fontheight = 10; fontwidth = 10; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { RECT rect; //获得客户区大小 HFONT hfont, hlastfont; //字体句柄 LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); //选择字体 lstrcpy(lf.lfFaceName, "Arial"); if(fontheight <= 90) { fontheight += 5; lf.lfHeight = fontheight; } else if((fontheight > 90)&&(fontheight < 170)) { lf.lfHeight = 180 - fontheight; fontheight += 5; } else { fontheight = 10; lf.lfHeight = fontheight; } lf.lfWeight = fontwidth; lf.lfEscapement = fontangle * 10; if(fontangle < 360) { fontangle += 5; } else { fontangle = 0; } //获得客户区大小 ::GetClientRect(Handle, &rect); Background->Canvas->FillRect(rect); hfont = CreateFontIndirect(&lf); //创建字体 //选择字体对象,并保存原字体对象 hlastfont = SelectObject(Background->Canvas->Handle, hfont); TextOut(Background->Canvas->Handle, rect.right/2, rect.bottom/2, text, lstrlen(text)); SelectObject(Background->Canvas->Handle, hlastfont); DeleteObject(hfont); Canvas->CopyRect(rect, Background->Canvas, rect); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { TRect rect; ::GetClientRect(Handle, &rect); Canvas->CopyRect(rect, Background->Canvas, rect); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { Invalidate(); } //---------------------------------------------------------------------------