DDB example for C++ Builder
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.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int MyFlags;
L_HBITMAP MyDDB;
L_HPALETTE MyPalette;
THandle MyDC;
Screen->Cursor = crHourGlass;
/*Copy the bitmap to the clipboard*/
MyFlags = COPY_EMPTY | COPY_DDB | COPY_PALETTE;
Lead1->Copy(MyFlags);
/*Paste the image onto the second bitmap.*/
if( Lead2->Paste(PASTE_ISREADY) == 0)
{
ShowMessage ("Invalid data on the clipboard");
}
else
{
Lead2->Paste(0);
}
/*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 = (L_HBITMAP)Lead2->GetDDB(MyDC);
/*Get the palette handle.*/
MyPalette = (L_HPALETTE)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;
}