Adding a Document Selector to a MDI Application | CodeGuru

Adding a Document Selector to a MDI Application

Document Selector is a Windows taskbar like control which enables user to quickly jump to a selected document easily in a MDI application. The idea came in my mind after using Editplus, a text editor from ES-Computing. I was seeking some help for the purpose as I was unable to write the whole thing from […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 11, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Document Selector is a Windows taskbar like control which enables user to quickly jump to a selected document easily in a MDI application. The idea came in my mind after using Editplus, a text editor from ES-Computing. I was seeking some help for the purpose as I was unable to write the whole thing from scratch. After searching a little, I found the article “A Switcher Control (like the Windows Task Bar)” at codeguru posted by Jimmy Brush. I modified the code as appropriate and got a working document selector which I am posting here.

In the beginning of writing the code, I was willing to make the Document selector as close as the taskbar in it’s functionality. But because of the complexity the spin button control was adding, I dropped the idea and added a Menu button to drop down a menu for unshown buttons. But soon I will post a updated article for the document selector with a spin button support too.

The future version of the Document bar will have following additional features :-

  • Support for image lists.
  • Support for both the Spin button control and menu button.
  • Docking document bar.
  • Automatic removal of buttons when the view is destroyed.
  • Support for context menu.

It will be soon posted in a month or two. (If you think that “soon” is too late, please don’t mind. I am just 19, and studying in a college. My exams are nearing over. That one month span is just for those exams.)

To add the document bar to your application, all you have to do is to take the five following steps :-

  • Include the following six files in your project and add the menubutton.bmp (or IDB_MENU_BUTTON if you downloaded the demo project) to your resource file.
    • DocSelect.cpp
    • DocSelect.h
    • MenuButton.cpp
    • MenuButton.h
    • SwitcherButton.cpp
    • SwitcherButton.h
  • Add a member of type CDocSelect to your CMainFrame class :-
    public:
     CDocSelector m_wndDocSelector;
    
  • Create the Bar Window in the CMainFrame OnCreate function:-
    m_wndDocSelector.Create(NULL, NULL, WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS |
                            CBRS_TOP, CRect(0,0,0,0), this, AFX_IDW_STATUS_BAR);
    m_wndDocSelector.SetBarStyle( CBRS_ALIGN_TOP );
    
  • Add a new button when it’s view is created, by overriding the OnInitialUpdate function in your view class :-
    void CDocumentBarView::OnInitialUpdate()
    {
     // Call base class's OnIntialUpdate First...
     CEditView::OnInitialUpdate();
    
     // Replace IDR_DOCUMETYPE with your Icon resource ID.
     ((CMainFrame*)AfxGetMainWnd())->m_wndDocSelector.AddButton( this, IDR_DOCUMETYPE );
    }
    
  • Remove button of the destroying view, by overriding the OnDestroy function in your view class :-
    void CDocumentBarView::OnDestroy()
    {
     ((CMainFrame*)AfxGetMainWnd())->m_wndDocSelector.RemoveButton( this );
    
     // Call base class's OnDestroy after removing button...
     CEditView::OnDestroy();
    }
    

All the selection and deselection process is handled by the document selector itself. You don’t have to override OnSetFocus and OnKillFocus to manually select or deselect a view’s button.

If you extend the document selector, please notify me of the changes and post me a copy. I will be thankful.

Downloads

Download Demo Project – 33 Kb
Download Source – 15 Kb

History

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.