SetWindowLong 给MDI窗体加背景

//给MDI窗体加背景 
//设置Form1窗体的FormStyle属性为fsMDIForm
//设置Form2窗体的FormStyle属性为fsMDIChild

// Image控件 Bmp格式图片

   private
      FClientInstance : TFarProc;
      FPrevClientProc : TFarProc;
       Procedure ClientWndProc( Var Message: TMessage);

procedure TForm1.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;
procedure TForm1.FormShow(Sender: TObject);
begin
  FClientInstance := MakeObjectInstance(ClientWndProc); //将自定义过程的地址入口存入PClientInstance中
  FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC)); //记录消息位置
  SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FClientInstance)); //重新载入窗口的消息并继续处理。
end;

//为非MDI窗体制作背景




你可能感兴趣的:(window)