Board index » delphi » BitBlt copies wrong canvas...

BitBlt copies wrong canvas...

I hop you can help me out here ... I'm creating a component and in the paint
procedure I have this code:

  ParentFormHDC := GetDC(Parent.Handle);
  BitBlt(bmp.canvas.handle, 0, 0, Width, Height, ParentFormHDC, Left, Top,
SRCCOPY);
  ReleaseDC(Parent.Handle, ParentFormHDC);

The idea is to copy the area behind my component, but instead of copying the
form, I get the background of my desktop. I guess that somehow the BitBlt is
done before the form is created.

Hope you have a solution!!

Thanks.

Mojo

 

Re:BitBlt copies wrong canvas...


Quote
Mojo <m...@2die4.com> wrote:

> The idea is to copy the area behind my component, but instead of
copying the
> form, I get the background of my desktop. I guess that somehow the
BitBlt is
> done before the form is created.

If I understand your question correctly you want to copy the area behind
your component. Here is a function that I use in some transparent
components I have written:

Quote

procedure DrawParentImage(Control: TControl; Dest: TCanvas);
var
  SaveIndex: Integer;
  DC: HDC;
  Point: TPoint;
begin
  with Control do
  begin
    if Parent = nil then
      Exit;
    DC := Dest.Handle;
    SaveIndex := SaveDC(DC);
    GetViewportOrgEx(DC, Point);
    SetViewportOrgEx(DC, Point.X - Left, Point.Y - Top, nil);
    IntersectClipRect(DC, 0, 0, Parent.ClientWidth,
Parent.ClientHeight);
    Parent.Perform(WM_ERASEBKGND, DC, 0);
    Parent.Perform(WM_PAINT, DC, 0);
    RestoreDC(DC, SaveIndex);
  end;
end;

<<

Bill

Other Threads