我想在子窗體關閉的時候,mdi主窗體執行一個事件,但是因為子窗體比較多,又不好寫在子窗體的事件裡面,請問如何在主窗體裡面獲取子窗體關閉的消息,還有最小化等等,拜託各位高手幫忙,特急!!!

解决方案 »

  1.   

    你可以用TActionList ,我觉得它能实现我们需要的大部分需求。至少MDI程序我用它都能满足。
      

  2.   

    你可以在子窗口的CLOSE里的事件里,自定义发一个消息给主窗口
    主窗口得到消息就可以处理事情。当然这个要你自己写了
      

  3.   

    使用Delphi的窗体控件恐怕够呛。可以写一个子窗体,再关闭时间里发消息给主窗体,别的子窗体都从它继承。WM_ParentNotify消息据说可以检测到子窗体的创建、释放、点击事件,但是我实际使用了一下,只能监测到点击事件。但是如果使用API函数,设置子窗体的父窗体句柄(Windows.SetParent(子窗体句柄,父窗体句柄),该消息处理函数就可以监测到子窗体的释放事件。但是,此时主窗体的客户区会改变——除了标题栏外,全都是客户区。想来是Delphi内部对该消息进行了处理。procedure WMParentNotify(var Msg: TWMParentNotify); message WM_PARENTNOTIFY;
    procedure TfrmMainFrame.WMParentNotify(var Msg: TWMParentNotify);
    begin
      if msg.Event=WM_DESTROY then //msg.Event总是为513。若是2,则是子窗体释放事件。
      begin
        showmessage('Child closed!');
      end;
    end;
      

  4.   


    function HookClientProc(hWnd: HWND;
                            uMsg: UINT;
                            wParam: WPARAM;
                            lParam: LPARAM): Integer;
    begin
      if uMsg = WM_MDIDESTROY then
        ShowMessage('WM_MDIDESTROY');
      Result := DefMDIChildProc(hWnd, uMsg, wParam, lParam)
    end;  hwndClient := Self.ClientHandle;
      lpfnClient := GetWindowLong(hwndClient, GWL_WNDPROC);
      SetWindowLong(hwndClient, GWL_WNDPROC, LPARAM(@HookClientProc));
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        New1: TMenuItem;
        procedure New1Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses Unit2;var
      lpfnClient: Pointer;function HookClientProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    begin
      if uMsg = WM_MDIDESTROY then
        ShowMessage('WM_MDIDESTROY');
      Result := CallWindowProc(Pointer(lpfnClient), hWnd, uMsg, wParam, lParam)
    end;procedure TForm1.New1Click(Sender: TObject);
    begin
      with TForm2.Create(Self) do
      begin
        Visible := True;
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      SetWindowLong(Self.ClientHandle, GWL_WNDPROC, Integer(lpfnClient));
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      lpfnClient := Pointer(GetWindowLong(Self.ClientHandle, GWL_WNDPROC));
      SetWindowLong(Self.ClientHandle, GWL_WNDPROC, LPARAM(@HookClientProc));
    end;end.
      

  6.   

    謝謝Intelement(桂子) ,搞定了,加分,請查收
      

  7.   

    再請問一下,如果讓一個dxflowchar的元件放在mdi窗口,然後字窗口都在他的上面呢