MDI主窗口单没有子窗口显示时,会有一大部分空白区域,我想显示些东西上去,不知该如何显示?在On Paint里写代码,能显示,但FORM的size改变后,显示的信息不能重画,该如何解决?

解决方案 »

  1.   

    对MDI主窗口编写OnResize事件的过程,调用Invalidate过程,使其重画,应该可以解决你的问题
      

  2.   

    ...  private    FClientInstance : TFarProc;
        FPrevClientProc : TFarProc;
        procedure ClientWndProc(var message:TMessage);
    ...
    procedure TMForm.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 ImgMain.Picture.Height do
              for Col := 0 to ClientWidth div ImgMain.Picture.Width do
                BitBlt(Dc,
                   Col * ImgMain.Picture.Width,
                   Row * ImgMain.Picture.Height,
                   ImgMain.Picture.Width,
                   ImgMain.Picture.Height,
                   ImgMain.Picture.Bitmap.Canvas.Handle,
                   0,
                   0,
                   SRCCOPY);
              Result := 1;
          end;
          else
            Result := CallWindowProc(FPrevClientProc,
                                     ClientHandle,
                                     Msg,
                                     wParam,
                                     lParam);
      end;
    end;
    procedure TMForm.FormCreate(Sender: TObject);
    begin
       FClientInstance := MakeObjectInstance(ClientWndProc);
       FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
       SetWindowLong(ClientHandle,GWL_WNDPROC, LongInt(FClientInstance));
    end;
      

  3.   

    在主窗體上放一個image控件。當没有子窗口显示时﹐就顯示該image(image1.visible:=true),當子窗口显示时,隱藏image(image1.visible:=false)。
      

  4.   

    在窗體上要加一個ImgMain:TImage對象,在ImgMain上加載一個圖片,以上是通過重寫窗體函數實現的
      

  5.   

    在JEDI的网站里有关于MDI窗体背景的控件(功能很全),而且有源码的,去下个来,就解决问题了。
      

  6.   

    //NewWinProc :=MakeObjectInstance(NewWinProcedure);
      //OldWinProc :=Pointer (SetWindowLong (ClientHandle,gwl_WndProc,Cardinal (NewWinProc)));
      //Canvas :=TCanvas.Create;
    {procedure TMainForm.NewWinProcedure(var Msg: TMessage);
    var
         BmpWidth,BmpHeight: Integer;
         I,J: Integer;
    begin
    //TODO -o: 在Client窗体上接受消息画图片
          Msg.Result :=CallWindowProc(OldWinProc,ClientHandle,
             Msg.Msg,Msg.WParam,Msg.LParam);
          if Msg.Msg = wm_EraseBkgnd then
          begin
             BmpWidth :=MainForm.ImgClient.Width;
             BmpHeight :=MainForm.ImgClient.Height;
             if (BmpWidth <> 0) and (BmpHeight <> 0)then
               Canvas.Handle :=Msg.WParam;
               for I := 0 to MainForm.ClientWidth div BmpWidth do
               for J := 0 to MainForm.ClientHeight div BmpHeight do
               Canvas.Draw(I * BmpWidth,J* BmpHeight,MainForm.ImgClient.Picture.Graphic);
          end;
    end;     }
      

  7.   

    MainForm.ImgClient.Picture.Graphic为预先存放在Image中的图片
      

  8.   

    不好意思,其实z_hongbao说的方法是完全可以的,但是因为当时我改了他程序的格式所以不行.我不明白为什么我直接响应WM_ERASEBKGND消息不行呢?
      procedure aaa(var message:TMessage); message WM_ERASEBKGND;然后在此过程里显示图片, 这样好像只是在FORM上闪了一下.我是菜鸟, 哪位能帮我解释一下我的这种方式跟z_hongbao说的重写窗体函数方式有什么不同?
      

  9.   

    自接复盖其刷子的图片就可以了。
    TfrmMain.FormCreate(Sender: TObject);
    begin
      Self.Brush.Bitmap := Image1.Picture.Bitmap;
    end;
      

  10.   

    为什么一定要用画的方法呢?可以用图片的方法:
    在FORM上放一个IMAGE(将VISIBLE设为FALSE),并加载一幅图
    (必须是BMP),在ONSHOW中添加代码:
    procedure TForm1.FormShow(Sender: TObject);
    begin
      Brush.Bitmap := Image1.Picture.Bitmap;
    end;
    不就可以了吗,费那个尽干什么
      

  11.   

    procedure ClientWndProc(var message:TMessage);0调用非客户区的刷新函数。
      

  12.   

    dickeybird888(于伟刚) 的方法很好