請先用編輯軟體將不顯示部分塗成藍色(Blue)
然後再表單上插入一個TImage物件,載入這張圖
然後再Form1的OnActivate事件填入
語法:
void __fastcall TForm1::FormActivate(TObject *Sender)
{
HRGN rgn1,rgn2;
int x,y,startx,endx;
if(rgn1!=0)DeleteObject(rgn1);
rgn1=0;
LockWindowUpdate(Handle);
for(y=0;y<Image1->Height-1;y++)
{
x=0;
startx=0;
endx=x;
do
{
while((Image1->Canvas->Pixels[x][y]==clBlue)&&(x<=Image1->Width)){x++;}
startx=x;
x++;
while((Image1->Canvas->Pixels[x][y]!=clBlue)&&(x<=Image1->Width)){x++;}
endx=x;
if(startx!=Image1->Width)
{
if(endx==Image1->Width)endx--;
if(rgn1==0)
{
rgn1=CreateRectRgn(startx+1,y,endx,y+1);
}
else
{
rgn2=CreateRectRgn(startx+1,y,endx,y+1);
if(rgn2!=0)
{
CombineRgn(rgn1,rgn1,rgn2,RGN_OR);
}
DeleteObject(rgn2);
}
}
}while(x<Image1->Width-1);
}
LockWindowUpdate(0);
SetWindowRgn(Handle,rgn1,true);
}
//---------------------------------------------------------------------------
Image1的OnDblClick事件填入(不填也行,只是要結束程式會有點麻煩)
語法:
void __fastcall TForm1::Image1DblClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
本程式節錄自RUN!PC 67期 李明樹先生發表