Questions about "establishing new documents fail"!

xiaoxiao2021-03-18  211

Analysis on "establishing an empty document failed"!

Many newcomers always do handle when they encounter such problems, if anyone has patience, look at the following article.

The emergence of such problems is mainly in Bool Cwinapp :: ProcessShellcommand (CCommandlineInfo & RCMDInfo);

The key content of the function:

Bool Bresult = true;

Switch (rcmdinfo.m_nshellcommand)

{

Case CCommandLineInfo :: Filenew: // New

IF (! AFXGetApp () -> oncmdmsg (id_file_new, 0, null, null)

ONFileNew ();

IF (m_pmainwnd == null)

BRESULT = FALSE;

Break;

Case CCommandLineInfo :: FileOpen:

IF (! OpenDocumentfile (rcmdinfo.m_strfilename))

BRESULT = FALSE;

Break;

Through the above content we can see: If there is no problem with the id_file_new, there is onfilenew ();

CWINAPP's default implementation of ONFileNew is to call m_pdocmanager-> onfilenew ();

We continue to analyze CDOCManager, what is it?

(First, explain that CDOCManager is the main function is to help CWINApp is the management document template list and registration file type.)

// If the template list is empty

IF (m_templatelist.isempty ())

{

TRACE0 ("Error: No Document Templates Registered with CWINApp./N);

AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC); // An error is reported. Here will not be reported to establish a new document error.

Return;

}

CDOCTemplate * ptemplate = (cdoctemplate *) m_templatelist.gethead ();

IF (M_TemplateList.getCount ()> 1)

{

// More one one document template to Choose from

// BRING UP DIALOG PROMPTING User

CNEWTYPEDLG DLG (& M_TemplateList);

INT NID = DLG.DOMODAL ();

IF (NID == IDOK)

PTEMPLATE = DLG.M_PSelectedTemplate;

Else

Return; // none - Cancel Operation

}

Assert (PTEMPLATE! = NULL);

Ask_KINDOF (CDOCTemplate, PTEMPLATE);

PTEMPLATE-> OpenDocumentFile (NULL);

Through the above code. We can see that CWINAPP ONFileNew and ONFileOpen call CDOCManager virtual functions onfilenew and ONFileOpen. And inside CDOCManager. Select different templates through template tables to call the document template's openDocumentFile ();

If the incoming parameter null means a new file.

Let's take a look at CDOCTemplate :: OpenDocumentFile () it is the most critical function. Because he is a virtual function, we consider CSINGEDEMPLATE :: OpenDocumentFile.

There is a code in this function:

Among them: AFX_IDP_FAILED_TO_CREATE_DOC is the resource ID of the character "establishment empty document failed"

// Create a new document

PDocument = cretenewdocument ();

Assert (pframe == null); // Will Be createBelow

Bcreated = true;

IF (pDocument == null)

{

AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC);

Return NULL;

}

Assert (pDocument == m_ponlydoc);

IF (pframe == null)

{

Assert (bcreated);

// Create Frame - SET As Main Document Frame

Bool bautodelete = pDocument-> m_bautodelete;

PDocument-> m_bautodelete = false;

// Don't Destroy if Something Goes WRONG

Pframe = CreateNewFrame (PDocument, NULL);

PDocument-> m_bautodelete = bautodelete;

IF (pframe == null)

{

AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC);

Delete pdocument; // evlicit delete on error

Return NULL;

}

Through observing the above code, we can easily see that there are two possible reasons: 1 CreateNewDocument Returns NULL 2

CreateNewFrame returns empty.

First seeing CreateNewDocument () Generally, this function has little failure. However, you can't fall lightly during debugging.

Take a look at CreateNewFrame () There is a function loadFrame is the source of this "establish a new document failed" error.

As long as it returns False, this prompt will pop up.

Let's take a look at LOADFrame () call CFrameWnd :: Create () to create a window, and create a window fails to return FASLE.

This is relatively simple to change.

Take a look at what the Create and CreateEx functions will know what is going on.

*********************************************************** *************

1 If you can't find the menu resource, return FALSE, also popped up "establishing an empty document failed"

Hinstance Hinst = AFXFINDRESOURCEHANDLE (LPSZMENUNAME, RT_MENU);

IF ((HMENU = :: loadMenu (hinst, lpszmenuname) == NULL)

{

Trace0 ("Warning: failed to load menu for cframewnd./N");

Postncdestroy (); // Perhaps delete the C ObjectReturn False;

}

2 Overload precomreateWindow and return False will also result in pop-up "establishment empty document failed"

3 Return -1 in OnCreate will also result in pop-up "establishment empty document failed".

*********************************************************** *****************

The above is the approximate cause of "establishing an empty document failure" problem. Perhaps there are other reasons. I will listen to it here.

转载请注明原文地址:https://www.9cbs.com/read-129989.html

New Post(0)