Question and Answer Database FAQ176D.txt — Displaying a bitmap on the client area of an MDI parent form. Category :Windows API Platform :All-32Bit Product : Question: How do I display a bitmap to the client area of an MDI parent form? Answer: Here are the necessary steps to add wallpaper to a MDI parent form: Create a new project Set the form's FormStyle to fsMDIForm Drop an image on the form and select a bitmap into it. 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); 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; 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)); 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. 4/2/99 11:38:30 AM
Last Modified: 01-SEP-99