Is there a correct way to make my file->open menu item be selectable whichever view I click in?
You can use the
ON_UPDATE_COMMAND_UI
macro to update your menu item state:
BEGIN_MESSAGE_MAP(CYourView, ...)
ON_UPDATE_COMMAND_UI(YOUR_MENU_ITEM_ID, OnUpdateYourCommand)
END_MESSAGE_MAP()
...
void CYourView::OnUpdateYourCommand(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}
But for opening files, it is better to:
- let your
CWinApp
derived class handle the
ID_FILE_OPEN
message.
- you may optionnaly override the
CDocument::OnOpenDocument
method to open the file manually.
- store all necessary data in your
CDocument
derived class.
- after the file is loaded, call
UpdateAllViews
.
- override
OnUpdate
method in your
CView
derived class to retrieve data from the
CDocument
object.
--------
Just add members in your document class. For example:
In your .h file:
class CYourDocument : public CDocument
{
public:
LPCTSTR GetViewTitle() const { return m_viewTitle; }
protected:
...
CString m_viewTitle;
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
};
In your .cpp file:
virtual BOOL CYourDocument::OnOpenDocument(LPCTSTR lpszPathName);
{
...
m_viewTitle = lpszPathName;
UpdateAllViews();
return TRUE;
}
Then in your CView .h file:
class CYourView : public CView
{
protected:
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
};
And in your CView .cpp file:
void CYourView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
CYourDocument* pDoc = (CYourDocument*)GetDocument();
SetWindowText(pDoc->GetViewTitle());
}