MFC如何通知文件改变(并显示*号)

MFC How to notify the document is changed (and display the *)

我习惯了,当我在 Microsoft Word 中更改文档时,它会在文件名附近显示一个 *,应用程序会自动知道我应该保存该文档。

如何在 MFC 中复制此行为并将这些更改通知我的文档 class,以便应用程序自动知道文档需要保存?

要通知文档它已被修改,您应该使用 CDocument::SetModified method, and to query whether it is modified, you can use the CDocument::IsModified. For the view, CView::OnUpdate 在文档更新时调用。

有点晚了,但我不得不做同样的事情。

设置文档的修改标志后,更改标题。这是一个例子: m_pDoc->SetModifiedFlag(bChanged);

        CString stTitle = m_pDoc->GetTitle();
        if (stTitle.Left(2) == _T(" *"))) {
            stTitle = stTitle.Left(stTitle.GetLength() - 2);
        }

        if (bChanged) {
            stTitle += _T(" *");
            m_pDoc->SetTitle(stTitle);
        }
        else {
            m_pDoc->SetTitle(stTitle);
        }