Author: Erwin Molendijk
How do I give my MDI window a background image or tile?
Answer:
This is a handy trick I found somewhere:
Put an image called Image1 on your main form.
Add the following routine to your main form:
Make sure you have the following variables in your main form object:
1
2 FClientInstance: TFarProc;
3 FPrevClientProc: TFarProc;
4
5 { MDI Background code }
6
7 procedure TMainForm.ClientWndProc(var message: TMessage);
8 var
9 Dc: hDC;
10 Row: Integer;
11 Col: Integer;
12 begin
13 with message do
14 case Msg of
15 WM_ERASEBKGND:
16 begin
17 Dc := TWMEraseBkGnd(message).Dc;
18 // Tile Image on DC
19 for Row := 0 to ClientHeight div Image1.Picture.Height do
20 for Col := 0 to ClientWidth div Image1.Picture.Width do
21 BitBlt(Dc,
22 Col * Image1.Picture.Width,
23 Row * Image1.Picture.Height,
24 Image1.Picture.Width,
25 Image1.Picture.Height,
26 Image1.Picture.Bitmap.Canvas.Handle,
27 0,
28 0,
29 SRCCOPY);
30 Result := 1;
31 end;
32 else // Pass on other msg's
33 Result := CallWindowProc(FPrevClientProc,
34 ClientHandle,
35 Msg,
36 wParam,
37 lParam);
38 end;
39 end;
And put this in your mainform OnShow event:
// MDI background tiles stuff, chain in de WndProc.
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
You now have a background!
|