You can arrange and dock multiple open documents to suit your needs. When you drag a document out of the main window, it is placed in a new floating window. In the VBA object model, these windows are called FrameWindows. The main frame window hosts the menu, status bar and all the dockers by default; and, when closed, causes the application to quit.
Application.FrameWork.MainFrameWindow represents the main frame window. Application.FrameWork.FrameWindows is a collection of all the frame windows, including the main frame and frame windows that host floating dockers and floating toolbars.
A DockHost is a linear docking region that can host one or more items which, in turn, could be DockHost or ViewHost items. A DockHost is similar to a one-dimensional table. It can be either horizontal or vertical. To create complicated two-dimensional layouts, you must nest the DockHosts.
The end-node of this DockHost tree is a ViewHost that contains one or more view windows. They are the tabbed window controls as seen in the UI with each document view as a tab.The following screen capture and diagram show an example of CorelDRAW containing 5 views and how this layout was achieved by using DockHosts and ViewHosts.
Sample layout:
A horizontal DockHost can contain only vertical DockHosts as immediate children. That is, you cannot split a cell inside a horizontal DockHost horizontally. Instead, you must insert another cell.
For more information about arranging open documents, see the following topics:
The following macro walks through the docking structure of each frame window and prints the layout structure (to the VBA Immediate window):
Sub DumpLayout() Dim s As String Dim f As FrameWindow For Each f In FrameWork.FrameWindows DumpFrameWindows f, 0, s Next f Debug.Print s End Sub Private Sub DumpDockItem(d As DockItem, indent As Long, ByRef s As String) If d.Type = cuiDockItemDockHost Then DumpDockHost d.DockHost, indent, s Else DumpViewHost d.ViewHost, indent, s End If End Sub Private Sub DumpDockHost(d As DockHost, indent As Long, ByRef s As String) If d Is Nothing Then Exit Sub Dim item As DockItem s = s & Space(indent) & "DockHost: " & d.ID & " - " & IIf(d.Orientation = _ cuiDockHostHorizontal, "H", "V") & vbCrLf For Each item In d.Children DumpDockItem item, indent + 2, s Next item End Sub Private Sub DumpViewWindow(w As ViewWindow, indent As Long, ByRef s As String) s = s & Space(indent) & "View: " & w.ID & " - Kind: " & w.Kind & _ " - " & w.Title & " / " & w.Description & vbCrLf End Sub Private Sub DumpViewHost(v As ViewHost, indent As Long, ByRef s As String) Dim w As ViewWindow s = s & Space(indent) & "ViewHost: " & v.ID & " - " & _ v.Views.Count & " view(s)" & vbCrLf For Each w In v.Views DumpViewWindow w, indent + 2, s Next End Sub Private Sub DumpFrameWindows(f As FrameWindow, indent As Long, ByRef s As String) s = s & Space(indent) & "FrameWindow: " & f.ID & " - " & IIf(f.IsMainFrame, _ "MainFrame", "Secondary") & vbCrLf DumpDockHost f.RootDockHost, indent + 2, s s = s & vbCrLf End Sub
If you run the DumpLayout macro for the Sample layout, you will see an output similar to the following:
FrameWindow: Framework_MainFrame - MainFrame DockHost: fc796773-64ff-4250-8d64-3bd07fd9352f - V DockHost: 1304df1c-d014-4daf-a755-c0fbbd983127 - H ViewHost: 5795efd1-b582-4b80-b05c-469450c3babd - 2 view(s) View: a961c249-6f05-4fbf-bb83-311d82c2444a - Kind: 1a9379f7-f018-3eb7-41e2-51436969b66f - Welcome Screen / View: 7a1d8b68-a01f-45ad-80bc-67a8ab2b1a86 - Kind: ab303a90-464d-5191-423f-613c4d1dcb2c - Untitled-4 / Untitled-4 DockHost: ed290c1b-448e-49e6-a1e4-fbee981b9545 - V ViewHost: 3ad110d1-94cb-4cab-9fab-2b431086aed4 - 1 view(s) View: 235e9f22-79c5-42ed-ad20-9fa17248c83c - Kind: ab303a90-464d-5191-423f-613c4d1dcb2c - Untitled-2 / Untitled-2 ViewHost: e713b707-d067-4ef8-a60e-7ff492b545df - 1 view(s) View: 338e338a-0f03-4013-965e-ceac1725bef9 - Kind: ab303a90-464d-5191-423f-613c4d1dcb2c - Untitled-3 / Untitled-3 ViewHost: 14f31f64-f810-4934-8c37-4f733393317e - 1 view(s) View: dedddb8a-3bd7-46bc-9e14-0179c00963db - Kind: ab303a90-464d-5191-423f-613c4d1dcb2c - Untitled-1 / Untitled-1
Each of the elements — FrameWindow, DockHost, ViewHost, ViewWindow— have unique IDs (GUID) that you can use to identify the elements. A view window also has a GUID that lets you differentiate the Welcome screen (kind: 1a9379f7-f018-3eb7-41e2-51436969b66f) from a regular document window (kind: ab303a90-464d-5191-423f-613c4d1dcb2c).
The following VBA example takes all the document views and places them all in one ViewHost in the main frame window. Any docked or floating documents are placed in the main frame.
Sub CombineAllViews() Dim vh As ViewHost, vhc As ViewHost Dim f As FrameWindow For Each f In FrameWork.FrameWindows For Each vh In f.ViewHosts If vhc Is Nothing Then If FrameWork.MainFrameWindow.ViewHosts.Count = 0 Then _ FrameWork.MainFrameWindow.RootDockHost.InsertViewHost vh, 1 Set vhc = vh Else vhc.InsertViewHost vh, vhc.Views.Count + 1 End If Next vh Next f End Sub
If the preceding macro is run on the Sample layout, the views are combined, and all open documents appear tabbed.
The open documents appear tabbed:
The following VBA example cascades all the views by extracting each view into its own floating window and arranging the views on top of the main frame window.
Sub CascadeViews() Dim vh As ViewHost, rc As ScreenRect, v As ViewWindow, fw As FrameWindow Set rc = FrameWork.MainFrameWindow.RootDockHost.Position.GetCopy rc.Resize rc.Width * 0.75, rc.Height * 0.75 For Each vh In FrameWork.MainFrameWindow.ViewHosts For Each v In vh.views Set fw = FrameWork.CreateFrameWindowForView(v) fw.Position.CopyAssign rc fw.Position.CopyAssign rc rc.Move rc.Left + 20, rc.Top + 20 Next v Next vh End Sub
Cascading views:
The following VBA macro tiles all the views inside the main frame window by using a grid.
Sub TileViews() Dim views As New Collection Dim fw As FrameWindow Dim vh As ViewHost, vw As ViewWindow, dh As DockHost Dim rows As Long, cols As Long Dim x As Long, y As Long, i As Long Dim r As DockItem, c As DockItem For Each fw In FrameWork.FrameWindows For Each vh In fw.ViewHosts For Each vw In vh.views views.Add vw Next vw Next vh Next fw If views.Count = 0 Then Exit Sub rows = CLng(Sqr(views.Count)) cols = (views.Count + rows - 1) \ rows Set fw = FrameWork.MainFrameWindow For y = 1 To rows i = (y - 1) * cols + 1 If dh Is Nothing Then If fw.RootDockHost.Orientation = cuiDockHostVertical Then Set vh = fw.RootDockHost.InsertView(views(i), y) Set dh = vh.DockHost Else Set vh = fw.RootDockHost.InsertView(views(i), _ 0, cuiDockOperationSplitTopLeft) Set dh = vh.DockHost End If Else Set vh = dh.InsertView(views(i), y) End If For x = 2 To cols i = i + 1 If i <= views.Count Then If dh.Children(y).Type = cuiDockItemDockHost Then dh.Children(y).DockHost.InsertView views(i), x Else dh.InsertView views(i), y, cuiDockOperationSplitBottomRight End If End If Next x Next y For Each r In fw.RootDockHost.Children r.RelativeSize = fw.RootDockHost.Position.Height / rows If r.Type = cuiDockItemDockHost Then For Each c In r.DockHost.Children c.RelativeSize = fw.RootDockHost.Position.Width / cols Next c End If Next r End Sub
Tiled views: