在MDI应用程序中,父窗口如何在子窗口关闭时得到通知,有源码最好!
在线等待!

解决方案 »

  1.   

    在窗口被关闭可以在closequery事件中写代码通知主窗体子窗体被切换也就是说当前激活的窗体有变化,具体的函数不是记得很清楚了
      

  2.   

    建立新的clientwindow的窗体过程,代码如下:private
       { Private declarations }
       FClientInstance : TFarProc;
       FPrevClientProc : TFarProc;
       procedure ClientWndProc(var aMessage: TMessage);
    implementationprocedure TfrmMForm.FormShow(Sender: TObject);
    begin
      FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
      FClientInstance := MakeObjectInstance(ClientWndProc);
      SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
    end;procedure TfrmMForm.ClientWndProc(var aMessage: TMessage);  procedure DoDefault;
      begin
         with aMessage do
           Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam,
    lParam);
      end;begin
      with aMessage do
        case Msg of
            WM_MDICREATE:
              begin
                {this event is when an application wants to create a child window}
                 {put your procedure here}
                DoDefault;
              end;
            WM_MDIDESTROY:
              begin
               {this event is when when an MDI Child is closed.So this event is what you need
               {put your procedure here}
                 DoDefault;
              end;
            WM_MDIACTIVATE:
              begin
                 DoDefault;
               {this event is when a new MDI child window is activated   
               {put your procedure here}
              end;
            WM_MDINEXT:
              begin
                 DoDefault;
               {this event is when a next or previous child window is activated }
               {put your procedure here}
              end;
            else
              DoDefault;
        end;
    end;Good Luck! 
     
    Comment from freshman3k 
     04/16/2002 10:19AM PST 
     
    Hello!Just in case you need more events there are 
    Follow should work:
    private
       { Private declarations }
       FClientInstance : TFarProc;
       FPrevClientProc : TFarProc;
       procedure ClientWndProc(var aMessage: TMessage);
    implementationprocedure TfrmMForm.FormShow(Sender: TObject);
    begin
      FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
      FClientInstance := MakeObjectInstance(ClientWndProc);
      SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
    end;procedure TfrmMForm.ClientWndProc(var aMessage: TMessage);  procedure DoDefault;
      begin
         with aMessage do
           Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam,
    lParam);
      end;begin
      with aMessage do
        case Msg of
            WM_MDICREATE:
              begin
                {this event is when an application wants to create a child window}
                 {put your procedure here}
                DoDefault;
              end;
            WM_MDIDESTROY:
              begin
               {this event is when when an MDI Child is closed.So this event is what you need
               {put your procedure here}
                 DoDefault;
              end;
            WM_MDIACTIVATE:
              begin
                 DoDefault;
               {this event is when a new MDI child window is activated   
               {put your procedure here}
              end;
            WM_MDINEXT:
              begin
                 DoDefault;
               {this event is when a next or previous child window is activated }
               {put your procedure here}
              end;
            else
              DoDefault;
        end;
    end;
      

  3.   

    我记得DELPHI目录下就有一个这样的实例啊!以前我见过的。
      

  4.   

    自己写代码控制啊,为什么非得找呢?
    先写一个复用的MDIChild,在close事件中将一个全局变量付值,
    再在MDI主窗口中处理就是了
    Onactive事件就可以啊