#include
#pragma hdrstop #include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; typedef struct
{
HDC hLCD;
AnsiString LCDText;
TFont *LCDFont;
TColor LCDLightPoint;
TColor LCDDarkPoint;
TColor LCDLine;
int PointSize;
} TLCD; Graphics::TBitmap *pScroll; __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{ } void __fastcall DrawLCDText(TLCD LCDData)
{
Graphics::TBitmap *pDark=new Graphics::TBitmap();
Graphics::TBitmap *pLight=new Graphics::TBitmap();
Graphics::TBitmap *pText=new Graphics::TBitmap(); //pDark->LoadFromFile("c:\\dark.bmp");
//pLight->LoadFromFile("c:\\light.bmp");
LCDData.PointSize= (LCDData.PointSize < 3) ? 3:LCDData.PointSize;
pLight->Width=LCDData.PointSize;
pDark->Width=LCDData.PointSize;
pLight->Height=LCDData.PointSize;
pDark->Height=LCDData.PointSize;
pDark->Canvas->Brush->Color=LCDData.LCDDarkPoint;
pDark->Canvas->Pen->Color=LCDData.LCDLine;
pDark->Canvas->Rectangle(0,0,pDark->Width,pDark->Height);
pLight->Canvas->Brush->Color=LCDData.LCDLightPoint;
pLight->Canvas->Pen->Color=LCDData.LCDLine;
pLight->Canvas->Rectangle(0,0,pLight->Width,pLight->Height); pText->Canvas->Font=LCDData.LCDFont;
pText->Width=pText->Canvas->TextWidth(LCDData.LCDText);
pText->Height=pText->Canvas->TextHeight(LCDData.LCDText);
pText->Canvas->Font->Color=LCDData.LCDLine;
pText->Canvas->TextOutA(0,0,LCDData.LCDText); for(int i=0;iHeight;i )
for(int j=0;jWidth;j )
{
if(pText->Canvas->Pixels[j][i] ==0)
BitBlt(LCDData.hLCD,j*(pLight->Width-1),i*(pLight->Height-1),pLight->Width,pLight->Height,pLight->Canvas->Handle,0,0,SRCCOPY);
else
BitBlt(LCDData.hLCD,j*(pDark->Width-1),i*(pDark->Height-1),pDark->Width,pDark->Height,pDark->Canvas->Handle,0,0,SRCCOPY);
}
delete pText;
delete pDark;
delete pLight; } void __fastcall TForm1::Button1Click(TObject *Sender)
{ TLCD lcdData;
lcdData.LCDText="Delphi K.Top 討論區 ";
lcdData.LCDFont=Form1->Font;
lcdData.LCDLightPoint=clLime;
lcdData.LCDDarkPoint=clGreen;
lcdData.LCDLine=clBlack;
lcdData.PointSize=4;
pScroll->Height=(Form1->Canvas->TextHeight(lcdData.LCDText) 1) * (lcdData.PointSize-1) 1;
pScroll->Width=(Form1->Canvas->TextWidth(lcdData.LCDText) 1) * (lcdData.PointSize-1) 1;
lcdData.hLCD=pScroll->Canvas->Handle; DrawLCDText(lcdData);
BitBlt(Form1->Canvas->Handle,0,0,pScroll->Width-3,pScroll->Height-
Timer1->Enabled=true;
} void __fastcall TForm1::FormCreate(TObject *Sender)
{
pScroll=new Graphics::TBitmap();
} void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete pScroll;
} void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
//左移
BitBlt(pScroll->Canvas->Handle,pScroll->Width-4,0,4,pScroll->Height,pScroll->Canvas->Handle,0,0,SRCCOPY);
BitBlt(pScroll->Canvas->Handle,0,0,pScroll->Width,pScroll->Height,pScroll->Canvas->Handle,3,0,SRCCOPY);
//右移
// BitBlt(pScroll->Canvas->Handle,3,0,pScroll->Width,pScroll->Height,pScroll->Canvas->Handle,0,0,SRCCOPY);
// BitBlt(pScroll->Canvas->Handle,0,0,4,pScroll->Height,pScroll->Canvas->Handle,pScroll->Width-4,0,SRCCOPY);
//上移
// BitBlt(pScroll->Canvas->Handle,0,pScroll->Height-4,pScroll->Width,4,pScroll->Canvas->Handle,0,0,SRCCOPY);
// BitBlt(pScroll->Canvas->Handle,0,0,pScroll->Width,pScroll->Height,pScroll->Canvas->Handle,0,3,SRCCOPY);
//下移
// BitBlt(pScroll->Canvas->Handle,0,3,pScroll->Width,pScroll->Height,pScroll->Canvas->Handle,0,0,SRCCOPY);
// BitBlt(pScroll->Canvas->Handle,0,0,pScroll->Width,4,pScroll->Canvas->Handle,0 ,pScroll->Height-4,SRCCOPY); BitBlt(Form1->Canvas->Handle,0,0,pScroll->Width-3,pScroll->Height-3,pScroll->Canvas->Handle,0,0,SRCCOPY); }
效果如下,不過字型越大速度越慢, 移動方面我是以PointSize=4去做的,所以如果變動了 PointSize 的大小,則需要做修改才能正常使用
![](http://www26.brinkster.com/bdanube/images/lcdText.gif)
發表人 - chunglin 於 2005/02/22 21:19:46 發表人 - chunglin 於 2005/02/22 21:27:39