- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Displaying a bitmap on the client area of an MDI parent form.

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:



  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.



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile