Tag Archives: enumerate documents

Enumerate documents in MDI applications

To enumerate all open documents in MDI (Multiple Document Interface) MFC applications we can do the following:

  1. Use CWinApp::GetFirstDocTemplatePosition and CWinApp::GetNextDocTemplate to get application document templates.
  2. For each document template, use CDocTemplate::GetFirstDocPosition and CDocTemplate::GetNextDoc to get contained documents.

Getting documents list

Example using documents list

This example calls CMyMDIApp::GetAllDocuments to get a list of all open documents, then fill a combobox control with document titles.
Also, it keeps the document pointers in each item data for further use (e.g. the application can activate the selected document at user request).


See also