tfrmDjNdb=Function (app:Tapplication;AOpenMode,AfrmStyle:integer;pFreeProc:Pointer):Tform; stdcall;  //调用注册动态库
  tSetOldApplication=Procedure ;stdcall;                 //重置主程序  tTestForm=Function (app:Tapplication;MDIform:TForm):Tform; stdcall;  //调用注册动态库
  frmTest: Tform;
implementation{$R *.DFM}
procedure TfrmKcMain.FormDestroy(Sender: TObject);
var SetOldApplication:tSetOldApplication;
begin
  inherited;
  @setOldApplication:=GetProcAddress(hKcNDBDLL,'SetOldApplication');
  if hKcNDBDLL<>0 then begin
    SetOldApplication;
    FreeLibrary (hKcNDBDLL);
   end;
  UnmapViewOfFile (gSLogDbInfor);
  CloseHandle (hKcMapFile);
end;//here load the mdichild form
procedure TfrmKcMain.ToolbarButton978Click(Sender: TObject);
var CallTestForm :tTestForm;
begin
  inherited;
  hKcNDBDLL:=LoadLibraryEx('KcNDB.dll',0,LOAD_WITH_ALTERED_SEARCH_PATH);
  if hKcNDBDLL<=0 then begin
    Raise  Exception.Create('not find dll_text!');
    Exit;
  end
  else begin
    try
      @CallTestForm:=GetProcAddress(hKcNDBDLL,'CallTestForm');
      frmTest:=callTestForm(application,Application.MainForm);
      frmTest.Show;
    exCept
      Raise Exception.Create('Dll Error');
      exit;
    end;
  end;end;
//调用函数,form没有用是测试用的
Function CallTestForm(App:TApplication;MDIform:TForm):TfrmTest;stdcall;
begin
  Application := App;
  if frmTest = nil then
  begin
    frmTest := TfrmTest.Create(application);
  end;
  result := frmTest;
end;
//处理主窗体中的image
procedure TfrmBase.FormCreate(Sender: TObject);
begin
   SetChildBorderIcons;
end;procedure TfrmBase.SetChildBorderIcons;
begin
case BorderStyle of
  bsToolWindow,
  bsSizeToolWin,
  bsDialog:
    begin
    FchildBorderIcons[1]:=True;
    FchildBorderIcons[2]:=False;
    FchildBorderIcons[3]:=False;
    end;
  bsNone:
    begin
    FchildBorderIcons[1]:=False;
    FchildBorderIcons[2]:=False;
    FchildBorderIcons[3]:=False;
    end;
else
    FchildBorderIcons[1]:=True;
    FchildBorderIcons[2]:=True;
    FchildBorderIcons[3]:=True;
    end;
if biSystemMenu in BorderIcons then
  begin
  FchildBorderIcons[1]:=FchildBorderIcons[1] and True;
  FchildBorderIcons[2]:=FchildBorderIcons[2] and True;
  FchildBorderIcons[3]:=FchildBorderIcons[3] and True;
  end
else
  begin
  FchildBorderIcons[1]:=FchildBorderIcons[1] and False;
  FchildBorderIcons[2]:=FchildBorderIcons[2] and False;
  FchildBorderIcons[3]:=FchildBorderIcons[3] and False;
  end;
if biMinimize in BorderIcons then
  begin
  FchildBorderIcons[3]:=FchildBorderIcons[3] and True;
  end
else
  begin
  FchildBorderIcons[3]:=FchildBorderIcons[3] and False;
  end;
if biMaximize in BorderIcons then
  begin
  FchildBorderIcons[2]:=FchildBorderIcons[2] and True;
  end
else
  begin
  FchildBorderIcons[2]:=FchildBorderIcons[2] and False;
  end;//if TFrmMain(Application.Mainform).MDIChildCount<2 then
//  begin
    TFrmMain(Application.Mainform).ChildImageClose.Visible:=FchildBorderIcons[1];
    TFrmMain(Application.Mainform).ChildImageClose.Enabled:=FchildBorderIcons[1];
    TFrmMain(Application.Mainform).ChildImageNormal.Visible  :=FchildBorderIcons[2];
    TFrmMain(Application.Mainform).ChildImageNormal.Enabled  :=FchildBorderIcons[2];
    TFrmMain(Application.Mainform).ChildImageMin.Visible  :=FchildBorderIcons[3];
    TFrmMain(Application.Mainform).ChildImageMin.Enabled  :=FchildBorderIcons[3];
//  end;end;procedure TfrmBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   if (Tfrmmain(Application.MainForm).MDIChildCount<2) and (action<>caNone) then
   begin
     Tfrmmain(Application.MainForm).ChildImageClose.Visible:=false;
     Tfrmmain(Application.MainForm).ChildImageClose.Enabled:=false;
     Tfrmmain(Application.MainForm).ChildImageMin.Visible  :=false;
     Tfrmmain(Application.MainForm).ChildImageMin.Enabled  :=false;
     Tfrmmain(Application.MainForm).ChildImageNormal.Visible  :=false;
     Tfrmmain(Application.MainForm).ChildImageNormal.Enabled  :=false;
   end;
   if (Tfrmmain(Application.MainForm).MDIChildCount<2)  then
   begin
     Tfrmmain(Application.MainForm).DockBar.Visible := True;
   end;end;procedure TfrmBase.UMyResize(Sender: TObject);
var
  i:Integer;
begin
TFrmMain(Application.Mainform).ChildImageMin.top:=TFrmMain(Application.Mainform).PanelTop.height-TFrmMain(Application.Mainform).ChildImageMin.height;
//TFrmMain(Application.Mainform).ChildImageMax.top:=TFrmMain(Application.Mainform).PanelTop.height-TFrmMain(Application.Mainform).ChildImageMax.height;
TFrmMain(Application.Mainform).ChildImageClose.top:=TFrmMain(Application.Mainform).PanelTop.height-TFrmMain(Application.Mainform).ChildImageClose.height;
TFrmMain(Application.Mainform).ChildImageNormal.top:=TFrmMain(Application.Mainform).PanelTop.height-TFrmMain(Application.Mainform).ChildImageNormal.height;i:=1;
if FchildBorderIcons[1] then
  begin
  TFrmMain(Application.Mainform).ChildImageClose.Left:=TFrmMain(Application.Mainform).Width-3-i*17-2;
  Inc(i);
  end;
if FchildBorderIcons[2] then
  begin
//  TFrmMain(Application.Mainform).ChildImageMax.Left:=TFrmMain(Application.Mainform).Width-3-i*17-2;
  TFrmMain(Application.Mainform).ChildImageNormal.Left:=TFrmMain(Application.Mainform).Width-3-i*17-2;
  Inc(i);
  end;
if FchildBorderIcons[3] then
  begin
  TFrmMain(Application.Mainform).ChildImageMin.Left:=TFrmMain(Application.Mainform).Width-3-i*17-2;
  end;if FchildBorderIcons[2] then
 if WindowState=wsMaximized then
  begin
  TFrmMain(Application.Mainform).ChildImageNormal.Enabled:=FchildBorderIcons[2];;
  TFrmMain(Application.Mainform).ChildImageNormal.Visible:=FchildBorderIcons[2];;
//  TFrmMain(Application.Mainform).ChildImageMax.Enabled:=False;
//  TFrmMain(Application.Mainform).ChildImageMax.Visible:=False;
  TFrmMain(Application.Mainform).ChildImageClose.Enabled:=True ;
  TFrmMain(Application.Mainform).ChildImageClose.Visible:=True ;
  TFrmMain(Application.Mainform).ChildImageMin.Enabled:=True;
  TFrmMain(Application.Mainform).ChildImageMin.Visible:=True;
  end
 else
  begin
  TFrmMain(Application.Mainform).ChildImageNormal.Enabled:=false;
  TFrmMain(Application.Mainform).ChildImageNormal.Visible:=false;
  TFrmMain(Application.Mainform).ChildImageMin.Enabled:=false;
  TFrmMain(Application.Mainform).ChildImageMin.Visible:=false;
//  TFrmMain(Application.Mainform).ChildImageMax.Enabled:=false;
//  TFrmMain(Application.Mainform).ChildImageMax.Visible:=false;
  TFrmMain(Application.Mainform).ChildImageClose.Enabled:=false;
  TFrmMain(Application.Mainform).ChildImageClose.Visible:=false;
  end;
end;procedure TfrmBase.FormResize(Sender: TObject);
begin
  UMyResize(sender);
end;

解决方案 »

  1.   

    现在的问题是dll中的WindowState总是和主程序中调用后生成的frmtest的状态不一样,或是不同步。
      

  2.   

    在 Form 的 OnResize 事件中取 WindowState 是 Resize 之前的,你应该改用消息:TfrmBase = class(TForm)
    ....
    private
      procedure WMSysCommand(var Message:TWMSysCommand); message WM_SYSCOMMAND;
    ...
    end;....
    procedure TfrmBase.WMSysCommand(var Message:TWMSysCommand); message WM_SYSCOMMAND;
    begin
      case Message.CmdType of
        SC_MINIMIZE: //最小化
        SC_MAXIMIZE: //最大化
        SC_RESTORE: //恢复
      end;
      inherited;
    end;
      

  3.   

    好象不行,如果说onResize中取得的是之后的状态,那为什么在主程序中的子窗体可以使主程序的图标改变,而动态连接库中的却不行?自窗体中使用的代码是相同的。
      

  4.   

    这是因为DLL中的Application对象和Exe中的Application对象根本是两回事
    可以通过参数把Exe中的APPLICATION对象传到DLL中,注意先保存DLL的APPLICATION,
    用完后再恢复。
      

  5.   

    DLL中的APPLICATION与EXE中的APPLICATION根本就是两回事,
    可以用参数把EXE中的APPLICATION传到DLL中。注意保存和恢复原来的APPLICATION
      

  6.   

    DLL中的APPLICATION与EXE中的APPLICATION根本就是两回事,
    可以用参数把EXE中的APPLICATION传到DLL中。注意保存和恢复原来的APPLICATION
      

  7.   

    我已经这么做了,我将exe中的Application传到dll中,并在释放时,将dll的application重值。如果不这么做,连mdichild方式都解决不了啊。我这么做仍然不行。不知道为什么。
    目前存在的问题是:
    1、调用dll产生的子窗体,不能象程序中创建的那样,控制主窗体上的最大化、最小化等按钮。
    2、正常情况下,系统产生了一个子窗体后,系统菜单的快捷键便不再第一时间响应,如果是Dll中产生的子窗体,则无法使主程序产生如此的变化。
    另外:to Zengyufeng:
    谢谢你,用你的方法确实可以让image显示出来,可是,它的事件不响应,有办法吗?
      

  8.   

    我觉得向主窗口传递自定义消息比较可靠。甚至在主窗口中还不能直接响应该消息,而应保存该消息用Timer事件等一下才处理该消息。我也曾经碰到过,只有用消息是最可靠的。