From: "Richard" Newsgroups: borland.public.delphi.graphics Subject: MDI and background image update (for anybody interested) Date: Thu, 21 Jun 2001 16:43:41 -0600 Lines: 106 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 207.34.113.138 Message-ID: <3b32782a$1_2@dnews> X-Trace: dnews 993163306 207.34.113.138 (21 Jun 2001 15:41:46 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:39982 I got some good code that allowed me to get background images drawn on my MDI application. My only problem was that if I moved a child window slightly off screen the vertical and/or horizontal scroll bars would appear but the background wasn't redrawn to fit. The same thing happened when you moved the child window back into the center of the parent and the scroll bars disappeared. I did some searching into the Windows messages and found that if I trapped the message WM_WINDOWPOSCHANGED and invalidated the client area then it would catch this event and my background always redrew properly. I'm not sure if this is the best way to do it but it works well for me. Here is the original code (with many thanks to Peter Below) with my code changes blocked with // New Code Richard Speiss unit Main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ToolWin, ComCtrls; type TForm1 = class(TForm) ToolBar1: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormResize(Sender: TObject); private { Private declarations } FLogoBitmap: TBitmap; FOldProc: Pointer; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} Function ClientWindowProc( wnd: HWND; msg: Cardinal; wparam, lparam:Integer): Integer; stdcall; Var f: TForm1; r: Trect; Begin f:= TForm1( GetWindowLong( wnd, GWL_USERDATA )); Case msg of WM_ERASEBKGND: Begin GetClientrect( wnd, r ); StretchBlt(wparam, r.left, r.top, r.right, r.bottom, f.FLogoBitmap.Canvas.Handle, 0, 0, f.FLogoBItmap.Width, f.FLogoBitmap.Height, SRCCOPY); result := 1; Exit; End; WM_HSCROLL, WM_VSCROLL: If LoWord( wparam )