You can iterate through your templates, documents, and views:
POSITION posTmpl = GetFirstDocTemplatePosition();
CDocTemplate *pTmpl = GetNextDocTemplate(posTmpl);
POSITION posDoc = pTmpl->GetFirstDocPosition();
CDocument *pDoc = tmpl->GetNextDoc(posDos);
POSITION posView = pDoc->GetFirstViewPosition();
CView *pView = pDoc->GetNextView(posView);
If you have only one template, you may remove the outer loop and use your
. If you have only one view per document, the innermost while condition can be replaced by an if condition.
The check if a view is already opened depends on your document/view organization. If no file is opened by your app, there is no document for the template. If a file is opened, you may compare the name using CDocument::GetPathName(). You may also check special state members of your document and view classes by casting the
return values to your derived classes.
Finally you can put the check into an
update handler. Then the command is disabled when the check fails indiacting this to the user: