Image as background of MDI-Form

Answer:
Here are the necessary steps to add wallpaper to a MDI parent
form:

1. Create a new project

2. Set the form's FormStyle to fsMDIForm

3. Drop an image on the form and select a bitmap into it.

4. Find the {Private Declarations }comment in the form's
   definition and add these lines right after it:

    FClientInstance : TFarProc;
    FPrevClientProc : TFarProc;
    procedure ClientWndProc(var Message: TMessage);
 

5. Find the "implementation" line and the {$R *.DFM}line that
   follows it. After that line, enter this code:

procedure TMainForm.ClientWndProc(var Message: TMessage);
var
  Dc : hDC;
  Row : Integer;
  Col : Integer;
begin
  with Message do
    case Msg of
      WM_ERASEBKGND:
      begin
        Dc := TWMEraseBkGnd(Message).Dc;
        for Row := 0 to ClientHeight div Image1.Picture.Height do
          for Col := 0 to ClientWidth div Image1.Picture.Width do
            BitBlt(Dc,
               Col * Image1.Picture.Width,
               Row * Image1.Picture.Height,
               Image1.Picture.Width,
               Image1.Picture.Height,
               Image1.Picture.Bitmap.Canvas.Handle,
               0,
               0,
               SRCCOPY);
          Result := 1;
      end;
      else
        Result := CallWindowProc(FPrevClientProc,
                                 ClientHandle,
                                 Msg,
                                 wParam,
                                 lParam);
  end;
end;
 

6. In the OnCreate method for the form, type the following lines
of code:

   FClientInstance := MakeObjectInstance(ClientWndProc);
   FPrevClientProc := Pointer(GetWindowLong(ClientHandle,
                              GWL_WNDPROC));
   SetWindowLong(ClientHandle,
                 GWL_WNDPROC, LongInt(FClientInstance));
 

7. Add a new form to your project and set its FormStyle property to
fsMDIChild.

Now you have a working MDI project with "wallpaper" where the image
bitmap is tiled to cover the MDI form's client area.
-----------
Subject:  Re: Image as background of MDI-Form

Investigate using the WM_ERASEBKGND message. You can then paint on the
application workspace, but you have to handle it in code, there's no
assigning a bitmap file to it and compiling it into the application. You
can, however, blit from another TBitmap _onto_ the surfaces canvas.
There's a good example of what you want to do in the "Delphi 2
Developers Guide", and I dare say it will be in the D4 one.
-----Original Message-----
Subject: Image as background of MDI-Form
 

Hi Delphians,

I need to show an image as background of a MDI-application.

First I tried to put a TImage component on it and in the
development-environment all seemed ok, but in run-time nothing was there
but grey. So I tried to put the image on a panel and definately put the
panel to the front. Now the image was there, but all MDI-children were
behind that Panel! I couldn't show one MDI-child! I searched and
searched and saw, that Delphi automatically creates (or it seems so) a
MDI-child, which is permanently there and in front of normal components
like the image.

So again the question: How can a bitmap be shown as background of a
MDI-Form???
----------
Subject:  Re: Image as background of MDI-Form

> Investigate using the WM_ERASEBKGND message......

No, I don't think that is the way to go.

There is another internal form (the Client Window form) which really is the
background of a MDI form. It is always on top client area of the MDI
mainform (and behind any child forms) and that is why painting on a MDI
form doesn't work.You can access this Client Window via
Mainform.clienthandle etc... See Delphi3.hlp
----------
Subject:  Re: Image as background of MDI-Form

This unit is a main MDI form unit. When run it roll's out a bitmap covering the entire form. Nothing else changes, meaning no problem with MDI children.

Never mind the other procedures.... :) ... And if you can't understand all the procedure names.. Well I use norwegian names... :)
---------------------

var
  FrmMain: TFrmMain;

implementation

uses om;

{$R *.DFM}

Procedure TFrmMain.ClientWndProc(Var Message : TMessage);
var
dc : hdc;
row, col : integer;
begin
with message do
     case msg of
     wm_erasebkgnd:
     begin
     dc := twmerasebkgnd(message).dc;
     for row := 0 to clientheight div wallpaper.picture.height do
       for col := 0 to clientwidth div wallpaper.picture.width do
          bitblt(dc, col * wallpaper.picture.width, row * wallpaper.picture.height,
          wallpaper.picture.width, wallpaper.picture.height,
          wallpaper.picture.bitmap.canvas.handle, 0, 0, srccopy);
       result := 1;
       end;
     else
     Result := Callwindowproc(FPrevclientproc, clienthandle,msg, wparam, lparam);
     end;
end;

procedure TFrmMain.AppVarsHint(Sender: TObject);
begin
Statuslinje.simpletext := application.hint;
end;

procedure TFrmMain.MenyOrdneikonerClick(Sender: TObject);
begin
Arrangeicons;
end;

procedure TFrmMain.MenyOverlappClick(Sender: TObject);
begin
Cascade;
end;

procedure TFrmMain.MenySidevedsidevanrettClick(Sender: TObject);
begin
Tilemode := tbHorizontal;
Tile;
end;

procedure TFrmMain.MenySidevedsidelodrettClick(Sender: TObject);
begin
Tilemode := tbVertical;
Tile;
end;

procedure TFrmMain.FormCreate(Sender: TObject);
begin
Fclientinstance := makeobjectinstance(clientwndproc);
FPrevClientProc := Pointer(Getwindowlong(Clienthandle, gwl_wndproc));
SetWindowLong(Clienthandle, gwl_wndproc, longint(Fclientinstance));
ArrangeIcons;
end;

procedure TFrmMain.MenyOmClick(Sender: TObject);
var
Vindu : Integer;
begin
FrmOm := TfrmOm.create(application);
Vindu := FrmOm.showmodal;
FrmOm.free;
end;

procedure TFrmMain.FormResize(Sender: TObject);
begin
arrangeicons;
end;

end.
 

----------