Tabs, toolbars, views, and MFC...
-
I'm relatively new to the doc/view architecture. I have a splitter and two views (vertical splitter). One of the views is straight-forward stuff that MFC does already. The other view is where I want to: 1) Show a toolbar with buttons at the top. 2) Show a tab control just below that. 3) Show another view below that. The tab control should switch between 2 to 4 views and should not have any funky borders. That is, the view currently showing below the tab control should look seamless with the tab control. I've been everywhere on Google and CP. The closest thing I've found is somewhere between CTabView[^], CSDITrueColor[^], and CMDITabs[^]. However, none of these solutions includes a toolbar. I could roll my own control, but I've never done that and that still doesn't tell me how to manage a view inside a control (unless you count the SubView[^] article that doesn't make much sense to me). I should mention that I don't need icons on my tabs, but I do need a toolbar (which none of the above links have). And I'm looking to do this without buying some expensive package or using WTL.
-
I'm relatively new to the doc/view architecture. I have a splitter and two views (vertical splitter). One of the views is straight-forward stuff that MFC does already. The other view is where I want to: 1) Show a toolbar with buttons at the top. 2) Show a tab control just below that. 3) Show another view below that. The tab control should switch between 2 to 4 views and should not have any funky borders. That is, the view currently showing below the tab control should look seamless with the tab control. I've been everywhere on Google and CP. The closest thing I've found is somewhere between CTabView[^], CSDITrueColor[^], and CMDITabs[^]. However, none of these solutions includes a toolbar. I could roll my own control, but I've never done that and that still doesn't tell me how to manage a view inside a control (unless you count the SubView[^] article that doesn't make much sense to me). I should mention that I don't need icons on my tabs, but I do need a toolbar (which none of the above links have). And I'm looking to do this without buying some expensive package or using WTL.
dontknowitall wrote:
...none of these solutions includes a toolbar...
The trick to making it easy with MFC is to use a frame window as a "view" and use the actual CView-derived window as a client window of that frame. Toolbars work nicely with frame windows (CFrameWnd-derived windows). So, for your situation, the windows you'll need (from bottom upward in z-order) are (1) A CFrameWnd-derived window containing a toolbar (2) A CTabCtrl-derived window used as the "view" (client window) of the frame window (1) (3) CView-derived window(s) for each tab created as children of the frame window (1) but always resized in response to WM_SIZE to fit the "client area" of the tab control (CTabCtrl::AdjustRect() gives you the tab control's "client" rect). Used this way, there's no need to worry about the toolbar. It stays anchored to the frame (unless you make it dockable) and the client window (tab control) is automagically kept sized within the remaining client area of the frame window. You just need to keep track of each tab's window, as is necessary with tab controls anyway.
dontknowitall wrote:
The tab control should switch between 2 to 4 views and should not have any funky borders
Not sure what you mean by "switch between 2 to 4 views " but you can control borders using the style flags used when creating the different windows. Hope this helps a bit, Mark
-
dontknowitall wrote:
...none of these solutions includes a toolbar...
The trick to making it easy with MFC is to use a frame window as a "view" and use the actual CView-derived window as a client window of that frame. Toolbars work nicely with frame windows (CFrameWnd-derived windows). So, for your situation, the windows you'll need (from bottom upward in z-order) are (1) A CFrameWnd-derived window containing a toolbar (2) A CTabCtrl-derived window used as the "view" (client window) of the frame window (1) (3) CView-derived window(s) for each tab created as children of the frame window (1) but always resized in response to WM_SIZE to fit the "client area" of the tab control (CTabCtrl::AdjustRect() gives you the tab control's "client" rect). Used this way, there's no need to worry about the toolbar. It stays anchored to the frame (unless you make it dockable) and the client window (tab control) is automagically kept sized within the remaining client area of the frame window. You just need to keep track of each tab's window, as is necessary with tab controls anyway.
dontknowitall wrote:
The tab control should switch between 2 to 4 views and should not have any funky borders
Not sure what you mean by "switch between 2 to 4 views " but you can control borders using the style flags used when creating the different windows. Hope this helps a bit, Mark
Thanks a ton. Your solution sounds a lot better (and simpler) than the solutions I was coming up with. Ignore the last bit you were confused over - it isn't important.