Click here to Skip to main content
Click here to Skip to main content

A multi document tabbed interface

By , 29 Jan 2000
 
  • Download demo project - 30 Kb
  • Download source files - 11 Kb
  • Download self-extracting installer - 363 Kb

    Sample Image - TabbedMDI.gif

    We have introduced a new interface extension for MDI (multiple document interface) based applications - MDI tabbed interface or MTI. This class is part of the Ultimate Toolbox class library and can be used freely.

    We haven't changed anything in the relationships between the main frame window (MDIFrame window) and its children (MDIChild windows). We added functionality that is usually overlooked when developing MDI applications.

    The MDIClient window which resides in the client area of the MDIFrame window manages MDIChild windows. Instead of just displaying the MDIClient window we also display a standard tab control (hence tabbed MDI) in which we create an item for every MDIChild window. The window icon and text will be associated with the corresponding tab item.

    Using the tab control you can switch quickly between MDIChild windows by just clicking on the tab item. If you double click over a tab item, the corresponding MDIChild window will be maximized/restored. And, finally, when any object is dragged over the tab control items (using standard OLE drag and drop) the corresponding MDIChild window will be activated.

    We use a standard tab control so you can customize its appearance using the standard set of relevant functions (refer for CTabCtrl description in the MFC documentation).

    We developed three classes in order to provide the above described functionality:

    COXTabWorkspaceDropTarget COleDropTarget derived class used to support the changing of active MDIChild when any object is dragged over tab control items (This is an internal class)
    COXTabWorkspace CTabCtrl derived class. Covers MDIClient area. For every MDIChild window there will be the tab item that will use window text and icon as item text and icon. Whenever you click on the item the coresponding child window will be activated. Whenever you double click on the item the corresponding MDIChild window will be maximized/restored
    COXTabClientWnd CWnd derived class. Subclasses MDIClient window. Manages the placement of the MDIClient and tab control regarding each other.

    Almost all the logic of the classes is implemented internally and there are few public members. Refer to COXTabWorkspace reference for the list of  functions available to customize the tab control appearance.

    COXTabClientWnd class has a few public functions (refer to COXTabClientWnd reference for details) but primarily you will be interested in the following ones:

    Attach()

    Detach()

    Below you two steps that should be taken in order to implement tabbed MDI interface in your MDI application

    1. In your CMainFrame class declare variable of COXTabClientWnd class:
      COXTabClientWnd m_MTIClientWnd;
              
    2. In your CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) function implementation add the following line of code:
      m_MTIClientWnd.Attach(this);

    That's it.

    Sample

    The TabbedMDI project included in the samples directory shows the class in action. There you will see how you can customize the tabbed MDI interface appearance.


    COXTabWorkspace

    SetOffset

    Sets the margin between tab control and MDIFrame client area borders

    GetOffset

    Retrieves the margin between tab control and MDIFrame client area borders

    AcceptDraggedObject

    Sets/Removes dragging object over support for the tab control

    IsAcceptingDraggedObject

    Retrieves the flag that specifies whether the control activate the corresponding MDIChild window when an object is dragged over tab control items.

    void SetOffset(const DWORD dwOffset)

    Parameters

    dwOffset

    offset in points from the MDIFrame window client area where the tab control will be displayed

    Remarks

    Sets the tab control offset from MDIFrame client area borders

    DWORD GetOffset() const

    Return Value

    offset in points from the MDIFrame window client area where the tab control will be displayed

    Remarks

    Retrievs the tab control offset from MDIFrame borders

    void AcceptDraggedObject(const BOOL bAccept=TRUE)

    Parameters

    bAccept if TRUE then when any object is dragged over tab items the corresponding MDIChild windows will be activated

    Remarks

    Set/Remove drag over object support for the tab control

    BOOL IsAcceptingDraggedObject() const

    Parameters

    bAccept

    if TRUE then when any object is dragged over tab items the corresponding MDIChild windows will be activated

    Return Value

    TRUE if when any object is dragged over tab items the corresponding MDIChild windows will be activated


    COXTabClientWnd

    Attach

    Substitutes the standard MDI interface with tabbed MDI

    Detach

    Restores the standard MDI interface

    IsAttached

    Retrieves the flag that specifies whether the standard MDI interface was substituted with enhanced tabbed MDI or not.

    GetTabCtrl

    Gets the fellow tab control

    GetParentFrame

    Gets the parent MDIFrame

    BOOL Attach(const CMDIFrameWnd* pParentFrame, DWORD dwTabCtrlStyle=DEFAULT_TABCTRLSTYLE)

    Parameters

    pParentFrame pointer to MDIFrame window of  the application
    dwTabCtrlStyle tab control styles that will be used while creating the tab control. Refer to the Windows SDK documentation for list of all available styles. The following styles are used by default:
    TCS_MULTILINE
    TCS_BOTTOM
    TCS_HOTTRACK
    TCS_SCROLLOPPOSITE
    TCS_RIGHTJUSTIFY

    Return Value

    TRUE if success or FALSE otherwise.

    Remarks

    Substitutes the standard MDI interface with enhanced tabbed MDI

    BOOL Detach()

    Return Value

    TRUE if successful or FALSE otherwise.

    Remarks

    Restore the standard MDI interface

    BOOL IsAttached() const

    Return Value

    TRUE if the tabbed MDI interface is active.

    Remarks

    Retrieves the flag that specifies whether the standard MDI interface was substituted with enhanced tabbed MDI or not.

    COXTabWorkspace* GetTabCtrl()

    Return Value

    pointer to the tab control

    Remarks

    Retrieves pointer to the tab control

    CMDIFrameWnd* GetParentFrame()

    Return Value

    pointer to the parent MDIFrame window or NULL if none was attached

    Remarks

    Retrieves pointer to the parent MDIFrame window

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Dundas Data Visualization
    United States United States
    Member
    Organisation
    3 members

    Since 1992 Dundas Data Visualization has been helping companies all over the world visualize their data. Dundas products have a global reputation of being the highest quality, and are all designed, built and tested to meet the strictest requirements that developers and business managers demand.
     
    Our showcase product is Dundas Dashboard, an easy-to-integrate digital dashboard software solution. Dundas Dashboard allows for the rapid and collaborative development of performance dashboards, helping companies leverage their business intelligence (BI) solutions.
     
    Our web-based dashboard software comes with wizard interfaces, and a unique Dundas DashFlowTM process, allowing for the simultaneous development of an executive dashboard by business analysts, IT staff and database administrators. It also uses premier charts, maps, gauges and graph controls, letting end-users visualize their data as required.
     
    Dundas also offers superb, world class consulting services for those companies that do not have the in-house expertise to implement their data visualization projects.
     
    The quality of our products in conjunction with our unmatched technical support, numerous awards and years of experience reflect Dundas Data Visualization's commitment to being the best!

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralMy vote of 5membervarandas7927 Nov '10 - 6:01 
    Very simple to use and very nice
    GeneralExcellent, slight fix thoughmemberJohn-Lucas Brown5 Jul '07 - 23:26 
    The application I've been developing changes the name of it's tab quite often. The problem occurs when the length of the string is quite different so changing is from “1” to “1234567890” the text remains centred as though it was displaying “1” so part of the text is hidden.
     
    I’ve tried various things to get it to sort itself out, and the solution I came up with (not particularly elegant though) is to change the size of the “tab window” and then change it back again.
     
    So in the function:

    void COXTabWorkspace::UpdateContents(BOOL bAddNewWindows/*=FALSE*/)
    {

     
    // update text if necessary
    if(m_arrTab[nFoundItem].sText!=sWindowText){
    m_arrTab[nFoundItem].sText=sWindowText;

    TC_ITEM tci;
    tci.mask=TCIF_TEXT;
    tci.pszText=(LPTSTR)(LPCTSTR)sWindowText;
    SetItem(nFoundItem,&tci);

    // INSERTED CODE BEGINS
    CRect cRect;
    GetClientRect(&cRect);
    SetWindowPos(NULL,0,0,cRect.Width(),cRect.Height()+2,SWP_NOZORDER);
    SetWindowPos(NULL,0,0,cRect.Width(),cRect.Height(),SWP_NOZORDER);
    // INSERTED CODE ENDS
     

     
    bRecalc=TRUE;
    }
    }

     

    Other than that works brilliantly, thank you very much!
     

    GeneralTab control redraw problemmemberatali6 Oct '04 - 11:27 
    I removed TCS_SCROLLOPPOSITE from the tab style, so all tabs are on the bottom line. However, now there is a problem redrawing tabs while MDI client windows are added. It shows when you add enough clients to fill two or more lines, and then if you add another window so that tabs are compressed on single line. The row of tabs that gets compressed is not properly updated, 1-2 pixel rows on top of each tab on the line still show old icon and tab divider. When full application window is redrawn, the tab control looks like it should be.
     
    This problem doesn't seem to show at all if TCS_SCROLLOPPOSITE is used.
     
    I'm using Windows 2000 but I remember same problems from NT 4.0 times. Is this Windows problem or COXTabWorkspace problem?
     
    Other than that, the stuff is great!
    Questionhow to add open documents as childs of Tree items??membermahatma_cis5 Aug '04 - 3:54 
    Hi
    I am having VC workspace like instant bar,that bar contains tree,how to add open documents as childs of this tree.?
    -MahatmaConfused | :confused:
    GeneralHelp Mememberasv9 Jun '04 - 8:39 
    I have seen ur article is Very Good.I have some problem.
    Problem: It is MDI Application.if i select New , I want open two views ie means here I was consider two view one Document.But Application having no of views.I am using splitter wnd.Now I want implement tab from one splittWnd to another.How to implement?
     
    dadsadasd
    GeneralProgramatically Switching Child Views in Tabbed MDImemberspeakeasy11 May '04 - 4:58 
    Hi,
     
    I was wondering if anyone here knew how to switch which of the tabs is being shown. I tried sending a WM_MDIACTIVATE message to activate the child window that I want but this didn't seem to work. I also tried the SetCurSel() function using the index of the tab but this didn't work either. As I understand it, this only changes the tab, not the view. But I am not sure.
     
    Any help would be appreciated.
     
    speakeasy

    GeneralTabbedMDI Demo BUG on XPmemberAmit Gefen8 Feb '04 - 20:05 
    When I "Upgrade" the project to XP "LOOK" using manifest file/rsrc it happen that the main freame client area around the m_MTIClientWnd is not getting updated during execution. When I move the mainframe with the mouse, that area reamain un-updated and memorize the background.
     
    The whole procedure og upgrade to XP look described in:
    http://www.codeguru.com/controls/xpstyle.html
     
    Is the problem with OXTabClientWnd class?
     
    Amit Gefen.
    Project Lead - Software Engineer
    Tel Aviv, Israel.

    GeneralRe: TabbedMDI Demo BUG on XPmemberIvor S. Sargoytchev9 Feb '04 - 4:25 
    Yes, it is a problem with this particular class since it was written long before Windows XP. I suggest you give the Ultimate ToolBox a try, it does not have this problem.
     

     
    Ivor S. Sargoytchev
    Dundas Software
    GeneralRe: TabbedMDI Demo BUG on XPmemberAmit Gefen10 Feb '04 - 4:22 
    Is it possible to you to fix this BUG in this particualr class?
     
    Amit Gefen.
    Project Lead - Software Engineer
    Tel Aviv, Israel.

    GeneralRe: TabbedMDI Demo BUG on XPmemberIvor S. Sargoytchev10 Feb '04 - 4:35 
    Yes, I will be doing this as soon as I have some free time.
     
    Ivor S. Sargoytchev
    Dundas Software

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web03 | 2.6.130523.1 | Last Updated 30 Jan 2000
    Article Copyright 2000 by Dundas Data Visualization
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid