DDB example for Delphi
This example copies the Lead1 bitmap to the clipboard as a DDB. It pastes the DDB into Lead2 and reverses the image. It then gets a DDB from Lead2, sets the same DDB to Lead1, and repaints.
procedure TForm1.Button3Click(Sender: TObject);
var
MyFlags: Integer;
MyDC, MyDDB, MyPalette: THandle;
begin
Screen.Cursor := crHourglass;
{Copy the bitmap to the clipboard}
MyFlags := COPY_EMPTY or COPY_DDB or COPY_PALETTE;
Lead1.Copy(MyFlags);
{Paste the image onto the second bitmap.}
If Lead2.Paste(PASTE_ISREADY) = 0 Then
begin
ShowMessage ('Invalid data on the clipboard');
end
Else
begin
Lead2.Paste(0);
end;
{Reverse the image so that we can see that it has changed.}
Lead2.Reverse;
{Make the second control visible so that we can get the client DC.}
Lead2.AutoScroll := False; {We do not need to see scrollbars.}
Lead2.Visible := True;
{Get the client DC and use it when creating a DDB.}
MyDC := Lead2.GetClientDC;
MyDDB := Lead2.GetDDB(MyDC);
{Get the palette handle.}
MyPalette := Lead2.GetBitmapPalette(MyDC);
{Keep the old display rectangles so that we do not have to recalculate.}
Lead1.AutoSetRects := False;
{Copy the DDB to the first control and repaint it.}
Lead1.SetDDB(MyDC, MyDDB, MyPalette);
Lead1.ForceRepaint;
{Clean up.}
Lead2.ReleaseClientDC;
Lead2.Visible := False;
Screen.Cursor := crDefault;
end;