Question and Answer Database
FAQ176D.txt Displaying a bitmap on the client area of an MDI parent form.
Category :Windows API
Platform :All
Product :All 32 bit
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:
[code lang=”delphi”] FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
procedure ClientWndProc(var Message: TMessage);
[/code]
5.Find the “implementation” line and the {$R *.DFM} line that
follows it. After that line, enter this code:
[code lang=”delphi”]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;
[/code]
6. In the OnCreate method for the form, type the following lines
of code:
[code lang=”delphi”] FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,
GWL_WNDPROC));
SetWindowLong(ClientHandle,
GWL_WNDPROC, LongInt(FClientInstance));
[/code]
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.
7/16/98 4:31:28 PM
Trademarks & Copyright © 1998 INPRISE Corporation. Last modified on
8-December-1998.
[tags]Delphi, Forms, Graphic[/tags]
0 Kommentare zu “MDI: Bitmap on MDI Background”