(1)在一个典型的MDI应用程序中,通过主窗体提供的属性和方法MDIChildCount,ActiveMDIChild等可以实现对子窗体的访问。
  当我们将子窗体封装在DLL中进行调用时,虽然已经创建了子窗体,但主窗体的MDIChildCount,ActiveMDIChild属性起不了作用了,此时EXE和DLL产生的是两个独立的应用。
  那么该如何去控制这些子窗体呢?   (2)MDI主窗口和子窗体的菜单是可以合并的,工具栏能吗?
  我目前的处理是当出现子窗体时,使主窗体的工具栏不可见,关闭子窗体时,让主窗体工具栏可见。这在一个EXE中没问题。但当调用的是DLL中的子窗体时,主菜单与工具栏间会出现一个缝隙,有什么解决办法?
  在单一EXE中,本可以
  执行子窗体工具栏  ToolbarSub.Parent:=Mainfrm;    //
  但该语句在调用DLL中的子窗体出错!//DLL中创建子窗体的函数
function CreateChild(ParentApplication: TApplication; ParentForm: TForm;WindowCaption:String;ParentHandle:HWND):HWND;stdcall;
begin
    Application:=ParentApplication;
    MyApplication:=ParentApplication;
    MyParentHandle:=ParentHandle;
    MyMainfrm:=ParentForm;
    Form1:=TForm1.Create(ParentForm);
    Form1.Caption:=WindowCaption;
//    Form1.ToolBar1.Parent:=ParentForm;     
    Form1.Show;
    Result:=Form1.Handle;
end;

解决方案 »

  1.   

    (1)//送你个完整的例子;只要自己创建一个TfrmDLLForm就可以了。library P_MyDLL;uses
      SysUtils,
      Forms,
      Windows,
      Messages,
      Classes,
      ActiveX,
      DLLFormUnit in 'DLLFormUnit.pas' {frmDLLForm};{$R *.res}var
      DLLApp: TApplication;
      DLLScr: TScreen;
    function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
    begin
      Application := App;
      Screen := Scr;  //CoInitialize(nil) ;
      Application.CreateForm(TfrmDLLForm, frmDLLForm);
      result:=frmDLLForm;end;procedure ExitDLL(Reason: Integer);
    begin
      if(Reason = DLL_PROCESS_ATTACH) then 
      begin
        CoInitialize(nil) ;
      end ;  if Reason = DLL_PROCESS_DETACH then
      begin
        Application := DLLApp;
        Screen := DLLScr;
        CoUninitialize ;
      end;
    end;exports
      CreateDLLForm;begin
      DLLApp := Application;
      DLLScr := Screen;
      DLLProc := @ExitDLL;end.
    (2)
    http://leonkim.blogchina.com/1480553.html 原创