怎样给一个mdi父窗体加上图片背景??我用了panel这个控件,又加了个image控件,但是子窗体却显示不出来了,为什么,请帮忙,谢谢。

解决方案 »

  1.   

    在Form中添加Image控件 
    设BMP图象 
    name为 IMG_BK 
    在Foem的Create事件中写入 
    Self.brush.bitmap:=img_bk.picture.bitmap; 
    上面的方法在Win95里面有问题。
    *****************
    在MDI程序中,由于MDI的主窗口一般的功能是提供子窗口显示的位置和提供菜单、工具条、状态条等,而窗口的客户区则一般不会有其它的用途,所以Image运行时会不见。不过要显示也可以,你可以试一下以下方法:
        第一步:创建一个新的工程。
        第二步:将Form1的FormStyle设置为fsMDIForm,设置成MDI的主窗口。
        第三步:在Form1上增加一个Image元件,并选择要设置的背景到Image的Picture中。
        第四步:在Form1的Private中定义:
            FClientInstance,
            FPrevClientProc : TFarProc;
            PROCEDURE ClientWndProc(VAR Message: TMessage);
        第五步:在实现(implementation)中加入上述过程的具体内容:
    PROCEDURE TForm1.ClientWndProc(VAR Message: TMessage);
    VAR
      MyDC : hDC;
      Ro, Co : Word;
    begin
      with Message do
        case Msg of
          WM_ERASEBKGND:
            begin
              MyDC := TWMEraseBkGnd(Message).DC;
              FOR Ro := 0 TO ClientHeight DIV Image1.Picture.Height DO
                FOR Co := 0 TO ClientWIDTH DIV Image1.Picture.Width DO
                  BitBlt(MyDC, Co*Image1.Picture.Width, Ro*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;    第六步:在Form1的创建事件中加入:
      FClientInstance := MakeObjectInstance(ClientWndProc);
      FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
      SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));    上面的步骤已经完成了MDI主窗口背景图案的设置,下面可以增加一个MDIChild窗口,实现MDI程序。  第七步:新增加一个Form,并将FormStyle设置为fsMDIChild。    现在你可以编译运行这个程序,你会发现,Image元件并不会在Form上显示出来,但是整个Form的客户区域被Image中的图像所铺满。
      

  2.   

    感觉在MDI窗口中加图片不是很理想,我的办法是另外加了一个子窗口,只要在主窗口的客户区被显示的时候就显示这个子窗口!
      

  3.   

    [Warning] main_unit.pas(101): Symbol 'MakeObjectInstance' is deprecated是这条警告。请帮忙解决。万分感激。
    to: Drate(鸟窝里的虫) 
      兄台说的不是很了解,不过感觉那样你那样还是不理想,不要见怪~~~,我觉的显示图片让人的感官比较舒服。
      

  4.   

    我把FClientInstance := MakeObjectInstance(ClientWndProc);改为了FClientInstance := forms.MakeObjectInstance(ClientWndProc);后警告消失。效果不错。万分感激。可不可一通过控件属性的设置实现这一功能呢?请大家帮忙想想。谢谢大家,谢谢: qiujsh(qiujsh) 。:)
      

  5.   

    ********************************首先********************************
    private
        foldclientproc,fnewclientproc:tfarproc;
        fdrawdc:hdc;
        procedure drawtiled;
        procedure clientwndproc(var message:tmessage);
        procedure createwnd;override;******************************然后**********************************
    implementation
    uses rsj_sjsr;
    procedure tmain.createwnd;
    begin
       inherited createwnd;
       fnewclientproc:=makeobjectinstance(clientwndproc);
       foldclientproc:=pointer(getwindowlong(clienthandle,gwl_wndproc));
       setwindowlong(clienthandle,gwl_wndproc,longint(fnewclientproc));
    end;procedure tmain.clientwndproc(var message:tmessage);
    begin
       case message.Msg of
          wm_erasebkgnd:
          begin
             callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
             fdrawdc:=twmerasebkgnd(message).dc;
             drawtiled;
             message.Result:=1;
          end;
          wm_vscroll,wm_hscroll:
          begin
             message.Result:=callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
             invalidaterect(clienthandle,nil,true);
          end;
          else
            message.Result:=callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
       end;
    end;procedure tmain.drawtiled;
    var
      row,col:integer;
      cr,ir:trect;
      numrows,numcols:integer;
    begin
       getwindowrect(clienthandle,cr);
       ir:=image1.clientrect;
       numrows:=cr.bottom div ir.bottom;
       numcols:=cr.right div ir.right;
       with image1 do
         for row:=0 to 4 do           // numrows+1
            for col:=0 to 7 do  // numcols+1
                bitblt(fdrawdc,col*picture.width,row*picture.height,picture.width,picture.height,picture.bitmap.canvas.handle,0,0,srccopy);
    end;
    *******************************最后*********************************
    就OK了!!!
      

  6.   

    to: budded(budded)
    直接加上image它不能充满整个客户区,上面距离top的高度为29,我的机器是这样的,不知你的怎么样??