// implement a helper funtion to tile the image
void TileBlt(HDC HDestDC, int DestWidth, int DestHeight, HDC HSourceDC,
int SourceWidth, int SourceHeight)
{
for (int y = 0; y < DestHeight; y = y + SourceHeight)
{
for (int x = 0; x < DestWidth; x = x + SourceWidth)
{
::BitBlt(HDestDC, x, y,
SourceWidth, SourceHeight,
HSourceDC, 0, 0,
SRCCOPY);
}
}
}
//---------------------------------------------------------------------------
// in the subclass procedure, draw the image
void __fastcall TMainForm::MDIClientWndProc(TMessage &Msg)
{
switch (Msg.Msg)
{
// draw the image to the device context of the
// client window
case WM_ERASEBKGND:
{
HDC Hdc = (HDC)Msg.WParam;
SelectPalette(Hdc, Image1->Picture->Bitmap->Palette, true);
RealizePalette(Hdc);
TileBlt(Hdc, Width, Height,
Image1->Canvas->Handle,
Image1->Picture->Bitmap->Width,
Image1->Picture->Bitmap->Height);