13,871
社区成员




void __fastcall TForm2::FormShow(TObject *Sender)
{
Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->PixelFormat = pf32bit;
bmp->Width = Width;
bmp->Height = Height;
this->PaintTo(bmp->Canvas,0,0);
for(int y=0; y<bmp->Height; y++)
{
RGBQUAD *pixel = (RGBQUAD*)bmp->ScanLine[y];
for(int x=0; x<bmp->Width; x++,pixel++)
{
//如果位于Image1范围内,则不透明,否则半透明
if(PtInRect(Image1->BoundsRect,Point(x,y)))
pixel->rgbReserved = 0xff;
else
{
pixel->rgbBlue /= 2;
pixel->rgbGreen /= 2;
pixel->rgbRed /= 2;
pixel->rgbReserved = 0x80;
}
}
}
DWORD dwExStyle = GetWindowLong(Handle, GWL_EXSTYLE);
if ((dwExStyle & WS_EX_LAYERED) != WS_EX_LAYERED) SetWindowLong(Handle, GWL_EXSTYLE, dwExStyle|WS_EX_LAYERED);
// 关联BMP数据到窗体
BLENDFUNCTION blend={
AC_SRC_OVER,0,0xFF,AC_SRC_ALPHA
};
POINT ptWinPos = {Left,Top};
SIZE sizeWindow = {Width, Height};
POINT ptSrc = {0, 0};
UpdateLayeredWindow(Handle, 0, &ptWinPos,
&sizeWindow, bmp->Canvas->Handle , &ptSrc, 0, &blend, ULW_ALPHA);
delete bmp;
}