创建一个MDI程序,当打开一个子窗体时,系统会自动在主窗体的windowmenu菜单中创建子窗体的列表,可通过点击窗体列表切换子窗体,非常奇怪的是,自动生成的窗体列表菜单项是访问不到的,只能列出自定义的菜单项。怎样通过代码访问这个子菜单列表,并且可以通过代码调用这个菜单窗体列表的Click事件,实现子窗体的切换;还有就是这个子菜单窗体列表是怎样自动生成的呢? 万分感谢!

解决方案 »

  1.   

    列表是发了消息让Windows实现的,以下是Delphi中的代码
    procedure TCustomForm.RefreshMDIMenu;
    var
      MenuHandle, WindowMenuHandle: HMenu;
      Redraw: Boolean;
    begin
      if (FormStyle = fsMDIForm) and (ClientHandle <> 0) then
      begin
        MenuHandle := 0;
        if Menu <> nil then MenuHandle := Menu.Handle;
        WindowMenuHandle := 0;
        if WindowMenu <> nil then WindowMenuHandle := WindowMenu.Handle;
        Redraw := Windows.GetMenu(Handle) <> MenuHandle;
        SendMessage(ClientHandle, WM_MDISETMENU, MenuHandle, WindowMenuHandle);//Here!!
        if Redraw then DrawMenuBar(Handle);
      end;
    end;
      

  2.   

    An application sends the WM_MDISETMENU message to a multiple document interface (MDI) client window to replace the entire menu of an MDI frame window, to replace the Window menu of the frame window, or both. 
      

  3.   

    TO blazingfire,
    子窗体菜单列表原来是这样生成的。怎样通过代码访问这个子菜单列表,并且可以通过代码调用这个菜单窗体列表的Click事件,实现子窗体的切换呢?
      

  4.   

    你也真是,直接访问子窗体不是更简单?!访问那个菜单不好弄的!下面是遍历所有的窗体并显示标题的代码
    var
      i: Integer;
      frmMDIChild: TForm;
    begin
      for i := 0 to MDIChildCount - 1 do
      begin
        frmMDIChild := MDIChildren[i];
        ShowMessage(frmMDIChild.Caption);
      end;
    end;
      

  5.   

    TO blazingfire, 
    唉,看来是没有办法的了。
      

  6.   

    其实blazingfire的作法我是知道的,我之所以想直接访问自动生成子窗体菜单列表是有特殊用途的。