Width;Height=Spirite->Height; for(int i=0;i Height;i++) { bkey=tru" />
龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

任意形状的窗体

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
Graphics::TBitmap* Spirite=new Graphics::TBitmap(); bool bkey=true; int iCount=0; TColor ColorKey=clWhite; Spirite->LoadFromFile("D:cbbak esourceraffic.bmp"); Width=Spirite->Width;Height=Spirite->Height; for(int i=0;i Height;i++) { bkey=tru

  Graphics::TBitmap* Spirite=new Graphics::TBitmap();

  

bool bkey=true;

  

int iCount=0;

  

TColor ColorKey=clWhite;

  

Spirite->LoadFromFile("D:cbbak

esourceraffic.bmp");

  

Width=Spirite->Width;Height=Spirite->Height;

  

for(int i=0;iHeight;i++)

  

{

  

bkey=true;

  

for(int j=0;jWidth;j++)

  

{

  

if(Spirite->Canvas->Pixels[j][i]==ColorKey)

  

bkey=true;

  

else{ if(bkey) iCount++; bkey=false;}

  

}

  

}

  

byte* pData;

  

RGNDATA* pRgnData;

  

RECT* pRect;

  

int iIndex=0,iLeft=0;

  

pData=new Byte[sizeof(RGNDATAHEADER)+sizeof(RECT)*iCount];

  

pRgnData=(RGNDATA* )pData;

  

pRect=(RECT* )(pData+sizeof(RGNDATAHEADER));

  

pRgnData->rdh.dwSize= sizeof( RGNDATAHEADER ) ;

  

pRgnData->rdh.iType= RDH_RECTANGLES;

  

pRgnData->rdh.nCount= iCount;

  

pRgnData->rdh.nRgnSize = sizeof( RECT )*iCount;

  

pRgnData->rdh.rcBound.left= 0;

  

pRgnData->rdh.rcBound.top= 0;

  

pRgnData->rdh.rcBound.right=Spirite->Width;

  

pRgnData->rdh.rcBound.bottom=Spirite->Height;

  

for( int i=Spirite->Height-1;i>=0;i--) //因为Bitmap位图在Y方向是颠倒的所以要从底部开始

  

{

  

bkey = TRUE ; iLeft = -1;

  

for( int j=0;jWidth;j++)

  

{

  

if(Spirite->Canvas->Pixels[j][i]==ColorKey )

  

{if( !bkey )

  

{pRect[iIndex].left =iLeft;

  

pRect[iIndex].right=j;

  

pRect[iIndex].top=Spirite->Width-i-1;

  

pRect[iIndex].bottom=Spirite->Height-i;

  

bkey=TRUE ;iIndex++ ;iLeft=-1;

  

}

  

}

  

else if(bkey){iLeft=j; bkey=false;}

  

}

  

if(iLeft>=0)

  

{

  

pRect[iIndex].left=iLeft ;

  

pRect[iIndex].right=Spirite->Width;

  

pRect[iIndex].top=i;

  

pRect[iIndex].bottom=i;

  

iIndex++;

  

}

  

}

  

bool br=ExtCreateRegion(NULL,sizeof( RGNDATAHEADER )+sizeof(RECT)*iCount,pRgnData);

  

if(!br) { ShowMessage("Create Form Failed."); Close(); }

  

delete[] pData;

  

精彩图集

赞助商链接