对于MDI不能用onPaint等,
我综合你的要求与我自己的程序,写了一个例子,这个例子与以前的不同
,以前的处理当子窗口移出主Form外时,一动滚动条,主窗口的位图就
错位,我现在所写这个例子不论怎样都不会出现主窗口图像错位。
请参考:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
ClientDC : HDC;
ClientCanvas : TBitmap;
FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
protected
Procedure ClientWndProc(VAR Message: TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Procedure TForm1.ClientWndProc(VAR Message: TMessage);
VAR
Ro, Co : Word;
L,T,w : integer;
LineTop : integer;
i:word;dy,y:real;
begin
with Messagedo
case Msg of
WM_ERASEBKGND:
begin
dy:=clientheight/256;
y:=0;
for i:=255do
wnto 0do
begin
ClientCanvas.canvas.brush.color:=$00000000 +i*$10000;
ClientCanvas.canvas.fillrect(rect(0,round
,clientwidth,round(y+dy)));
y:=y+dy;
end;
ClientCanvas.Canvas.Brush.Style := bsclear;
ClientCanvas.Canvas.Handle := ClientDC;
ClientCanvas.Canvas.Font.Color := clWhite;
ClientCanvas.Canvas.Font.size :=68;
w := ClientCanvas.Canvas.TextWidth('application');
L := (ClientWidth-w) div 2;
T := (ClientHeight -ClientCanvas.Canvas.TextHeight('FTitle')-40) div 2;
ClientCanvas.Canvas.TextOut(L,T,'application');
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
end;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDC := GetDc(ClientHandle);
ClientCanvas := TBitmap.Create;
ClientCanvas.Canvas.Handle := ClientDC;
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ReleaseDC(ClientHandle,ClientDC);
end;
end.