<>Create memory DCs and BitBlt to the screen with BCB. </P>0 D3 ^' B$ k+ H# N8 X" B8 E
<>Answer: The VCL TBitmap class contains a Canvas that encapsulates a memory DC for the bitmap. You can create a memory DC by creating a TBitmap object and drawing on its canvas. </P>$ p s V$ ^( l2 v) c/ V# G
<>void __fastcall TForm1::FormPaint(TObject *Sender)1 F7 v' F5 d# f) {+ A7 q! J
{3 q3 G, n+ A: F+ W0 E1 r0 Y5 r9 H
Graphics::TBitmap *bmp = new Graphics::TBitmap;7 }3 V! a3 g- R' J3 ~: G: x9 O$ `
bmp->Width = ClientWidth; 6 ]/ }/ A! L6 P$ E( y Z- a bmp->Height = ClientHeight; 8 i6 J9 V/ M7 n/ [ bmp->Canvas->Rectangle(0,0,ClientWidth/2, ClientHeight/2); ( U! J: K7 t4 q+ e Canvas->Draw(0,0,bmp);( F# e0 i+ \1 Y* F
delete bmp;- v! V: B$ Z9 |( i$ i; p
}</P>, v; O" B- F* f' J6 O
<>Notes: The Canvas property of TBitmap is NULL until you use the Canvas for the first time. In the code above, Canvas is NULL until the Rectangle call. It doesn't matter how you access the Canvas. The Canvas is created in the first call to the GetCanvas function (the read function for the Canvas property). </P> & m! X$ ?7 C9 [. f" @) }9 V% R<>The Draw method of TCanvas results in an API StretchBlt function call (StretchBlt will be called if source graphic is a bitmap, DrawIcon will be called if the graphic is an icon). StretchBlt blasts the contents of the memory bitmap into the display canvas. The CopyRect method of TCanvas also calls the StretchBlt function. However, CopyRect copies from a source Canvas into another Canvas, and the source Canvas does not have to be the same size as the destination. </P> ) h8 ]( J4 C* N+ a0 m# p<>Setting the Width and Height of the TBitmap object is important when you are not loading a bitmap image into the object. If you do load a bitmap into the object from a resource or BMP file, the Width and Height properties will be set to match the loaded image. In this case, omit the assignments to Height and Width. For example: </P>9 g* c8 N0 H* f% s1 `1 w
<>Graphics::TBitmap *bmp = new Graphics::TBitmap;& t1 O6 L' l3 b. J" ~; z
bmp->LoadFromResourceName( (int) HInstance, "IDD_BITMAP1");6 n2 k% T/ R; P* T+ L% G
bmp->Canvas->Rectangle(10,10,ClientWidth/2, ClientHeight/2);) R; \) s D' R1 L/ B
Canvas->Draw(0,0,bmp); 4 z6 s+ t9 \, vdelete bmp;</P>