This phase of the example shows the creation of a bitmap, the creation of an off-screen graphics device and graphics context for it, and the use of that graphics context to draw to the bitmap. Once a graphics context has been established for the bitmap, any of the GDI drawing functions can be used on the bitmap, as if it were the more common graphics context — the screen.
// create a bitmap to be used off-screen
CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
User::LeaveIfError(offScreenBitmap->Create(TSize(100,100),EColor256));
CleanupStack::PushL(offScreenBitmap);
// create an off-screen device and context
CGraphicsContext* bitmapContext=NULL;
CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(offScreenBitmap);
CleanupStack::PushL(bitmapDevice);
User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
CleanupStack::PushL(bitmapContext);
// draw something on the bitmap
TRect rect(0,0,100,100);
bitmapContext->SetBrushColor(KRgbRed);
bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
bitmapContext->DrawRect(rect); // a filled red rectangle
// now do what you want with it, such as blitting to the screen
gc.BitBlt(TPoint(20,20),offScreenBitmap);
// cleanup
CleanupStack::PopAndDestroy(3);
...