user3396028
user3396028

Reputation: 37

Performing an operation straight after loading a new document

I'm trying to perform a delete file operation straight after i load a new document. Is this possible? I tried:

BOOL CEmergenceDoc::OnNewDocument()  
{
    if (!CRichEditDoc::OnNewDocument())
        return FALSE;

CString title = CEmergenceView::GetView()->GetDoc()->GetTitle();

CStringA sB(title);
    const char* pszC = sB;
    char* pszD = const_cast<char*>(pszC);

    if(std::ifstream(pszD) ) {
        CEmergenceDoc::isNewFile = false;
    DeleteFile(title);
}

    return TRUE;
  }

but this gives me a debug assertion error.

EDIT:

After a bit more digging I've discovered that the debug assertion error is being displayed because I am calling the view before the view has been loaded. But then where can I put this code so that it executes straight after a new document and view has been loaded?

Upvotes: 0

Views: 43

Answers (1)

uesp
uesp

Reputation: 6204

If you really need the view then you can use CView::OnInitialUpdate().

I'm not exactly sure what you're trying to do but I would question whether you actually need the view. Can't you just do:

 CString title = GetTitle();

assuming that CEmergenceDoc derives from CDocument. Or are you trying to get the document title from the currently displayed view for another document?

Upvotes: 1

Related Questions