procedure TShadow.Paint;
var
DC, maskDC: HDC;
bmp, Mask, Image: HBITMAP;
Ind: Integer;
BkColor: COLORREF;
begin
if FSource = nil then Exit;
DC:=GetDC(0);
Mask:=CreateBitmap(Width, Height,1,1,nil);
Image := CreateCompatibleBitmap(DC, Width, Height);
bmp := CreateCompatibleBitmap(DC, Width, Height);
ReleaseDC(0, DC);
DC:=CreateCompatibleDC(Canvas.Handle);
maskDC:=CreateCompatibleDC(Canvas.Handle);
try
SelectObject(maskDC, bmp);
Ind:=SaveDC(maskDC);
FSource.Perform(WM_PAINT, maskDC, 0);
RestoreDC(maskDC, Ind);
SelectObject(DC, Image);
FillRect(DC, ClientRect, GetStockObject(WHITE_BRUSH));
Ind:=SaveDC(DC);
FSource.Perform(WM_PAINT, DC, 0);
RestoreDC(DC, Ind);
//Create mask
BitBlt(DC,0,0, Width, Height, maskDC, 0,0, SRCINVERT);
SelectObject(maskDC, Mask);
BkColor := SetBkColor(DC, $ffffff);
BitBlt(maskDC, 0, 0, Width, Height, DC, 0, 0, SrcCopy);
SetBkColor(DC, BkColor);
//In this place you can transform the appearence of the source to create more sophisticated shadow (inverting source, reduce intesity, brightness):
Ind:=SaveDC(DC);
FSource.Perform(WM_PAINT, DC, 0);
RestoreDC(DC, Ind);
BitBlt(DC, 0,0, Width, Height, DC, 0,0, DSTINVERT);//Inverting
//... or simple fill out masked area.
// FillRect(DC, Rect(0,0,Width, Height), Canvas.Brush.Handle);
MaskBlt(DC, 0,0, Width, Height, DC, 0,0, Mask, 0, 0, MAKEROP4(BLACKNESS,SRCCOPY));
MaskBlt(Canvas.Handle, 0,0, Width, Height, DC, 0,0, Mask, 0, 0, MAKEROP4(SRCPAINT,SRCCOPY));
finally
//Clear all
...
end;
end;
**********
Örnek 2
procedure TShadow.Paint;
var
DC, maskDC: HDC;
bmp, Mask, Image: HBITMAP;
Ind: Integer;
BkColor: COLORREF;
begin
if FSource = nil then Exit;
DC:=GetDC(0);
Mask:=CreateBitmap(Width, Height,1,1,nil);
Image := CreateCompatibleBitmap(DC, Width, Height);
bmp := CreateCompatibleBitmap(DC, Width, Height);
ReleaseDC(0, DC);
DC:=CreateCompatibleDC(Canvas.Handle);
maskDC:=CreateCompatibleDC(Canvas.Handle);
try
SelectObject(maskDC, bmp);
Ind:=SaveDC(maskDC);
FSource.Perform(WM_PAINT, maskDC, 0);
RestoreDC(maskDC, Ind);
SelectObject(DC, Image);
FillRect(DC, ClientRect, GetStockObject(WHITE_BRUSH));
Ind:=SaveDC(DC);
FSource.Perform(WM_PAINT, DC, 0);
RestoreDC(DC, Ind);
//Create mask
BitBlt(DC,0,0, Width, Height, maskDC, 0,0, SRCINVERT);
SelectObject(maskDC, Mask);
BkColor := SetBkColor(DC, $ffffff);
BitBlt(maskDC, 0, 0, Width, Height, DC, 0, 0, SrcCopy);
SetBkColor(DC, BkColor);
//In this place you can transform the appearence of the source to create more sophisticated shadow (inverting source, reduce intesity, brightness):
Ind:=SaveDC(DC);
FSource.Perform(WM_PAINT, DC, 0);
RestoreDC(DC, Ind);
BitBlt(DC, 0,0, Width, Height, DC, 0,0, DSTINVERT);//Inverting
//... or simple fill out masked area.
// FillRect(DC, Rect(0,0,Width, Height), Canvas.Brush.Handle);
MaskBlt(DC, 0,0, Width, Height, DC, 0,0, Mask, 0, 0, MAKEROP4(BLACKNESS,SRCCOPY));
MaskBlt(Canvas.Handle, 0,0, Width, Height, DC, 0,0, Mask, 0, 0, MAKEROP4(SRCPAINT,SRCCOPY));
finally
//Clear all
...
end;
end;