//---------------------------------------------------------------------------
//
in source file...
//
subclass the client window
__fastcall TMainForm::TMainForm(TComponent
*Owner)
:
TForm(Owner)
{
NewClientWP
= (FARPROC)MakeObjectInstance(MDIClientWndProc);
OldClientWP
= (FARPROC)SetWindowLong(ClientHandle, GWL_WNDPROC,
(LONG)NewClientWP);
}
//---------------------------------------------------------------------------
//
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);
Msg.Result = 0;
return;
}
// handle the palette changes
case WM_QUERYNEWPALETTE:
{
HDC Hdc = GetDC(ClientHandle);
SelectPalette(Hdc, Image1->Picture->Bitmap->Palette, true);
RealizePalette(Hdc);
InvalidateRect(ClientHandle, NULL, true);
ReleaseDC(ClientHandle, Hdc);
Msg.Result = 0;
return;
}
case WM_PALETTECHANGED:
{
if ((HWND)Msg.WParam != ClientHandle)
{
HDC Hdc = GetDC(ClientHandle);
SelectPalette(Hdc, Image1->Picture->Bitmap->Palette, true);
RealizePalette(Hdc);
UpdateColors(Hdc);
ReleaseDC(ClientHandle, Hdc);
}
Msg.Result = 0;
return;
}
// refresh the image upon scrolling
case WM_HSCROLL:
case WM_VSCROLL:
{
InvalidateRect(ClientHandle, NULL, true);
break;
}
// un-subclass the client window
case WM_DESTROY:
{
SetWindowLong(ClientHandle, GWL_WNDPROC, (LONG)OldClientWP);
FreeObjectInstance(NewClientWP);
}
}
// call the default window procedure
Msg.Result = CallWindowProc(OldClientWP, ClientHandle, Msg.Msg,
Msg.WParam, Msg.LParam);
}
//---------------------------------------------------------------------------
|