Changing the SDI documents titles using PreCreateWindow as suggested by documentations

  • Thread starter Thread starter sbrothy
  • Start date Start date
S

sbrothy

Guest
I want to connect the main SDI window with a CDockablePane. I thought a GUID might do the trick. In order to see the result I want to change the title of the current document to include the GUID, but it seems that when PreCreateWindow (ANY PrecreateWindow, ChilFrm, CMainFrame, you name it) is called, the Document isnt created yet and the I want to use the GUID to identify the document.

Code:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWndEx::PreCreateWindow(cs) )
return FALSE;

cs.style &= ~(LONG)FWS_ADDTOTITLE;

CMainFrame *pFrm = GetMainFrame();

CHermesDoc *pDoc = reinterpret_cast<CHermesDoc *>(GetMainFrame()->GetActiveDocument());
ASSERT(pDoc);
ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CHermesDoc)));

GUID *pGUID = pDoc->GetID();
TRACE("\t%s\n", GUIDAsString(*pGUID));

CString strName;
strName.Format(AFX_IDS_APP_TITLE, GUIDAsString(*pGUID));
_tprintf(_T("%s"), (LPCTSTR)strName);

TRACE("\t%s\n", strName);

return TRUE;
}

This fails because the CDocument hasn´t been created yet, and as such the GetDocument call returns a nullptr.

I´ve tried doing this after OnCreate has been cak'lled but with the same result. How can I change the caption of the CView-derivative based on an ID created in the CDocument=


Regards.

Continue reading...
 
Back
Top