MFC MDI document name

Posted on 2009-04-23
Last Modified: 2013-11-20
Dear Experts

In an MFC MDI application I have made an import function where a modified CFileOpenDialog gets some information about the file I am about to import. In MyDocument.cpp I have an import function, where the dialog object is instantiated and displayed. It goes like this:

//..... some stuff

                     ImportExportTimeSeriesDlg OpenDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,ImportExportFilterStr);
      if( OpenDlg.DoModal() == IDOK )
            CWaitCursor wait;
            strFileName = OpenDlg.GetPathName();
            std::string std_strFileName = CStringA(strFileName);
            strFileExt = OpenDlg.GetFileExt();
            iSeries = timeseries<double>(std_strFileName,OpenDlg.m_Delimiter,OpenDlg.m_TimeFormat,OpenDlg.m_NaN);

//... some other stuff

When this document is finally displayed in the application, the title is not only what gets out of OpenDlg.GetFileName(), but it has a ":1" appended at the end. This I would like to remove (example: if the file I'm importing is called "test.txt" the name displayed right now by the application is "test.txt:1" I would like "test.txt")

Am I naming the document the wrong way, and how to avoid getting this extra :1 in the file name?

Since I guess (but am not sure) it could have something to do the way I "register" the document in my app. I have posted that part of my CMyApp.cpp here. The line with pNewSeriesDoc->Import(); is what calls the function with the code snippet from above

void CMyApp::ImportTimeSeries()

      POSITION pos=GetFirstDocTemplatePosition();
      if(pos==NULL) {
            // error //
      CDocTemplate *pdTemp=GetNextDocTemplate(pos);
      CChildFrame *pChildFrm;         
      CDocument *pNewDoc =pdTemp->CreateNewDocument();
      pChildFrm =(CChildFrame*)pdTemp->CreateNewFrame(pNewDoc,NULL);
      CSeriesDoc *pNewSeriesDoc = STATIC_DOWNCAST(CSeriesDoc,pNewDoc);
      ASSERT(pNewSeriesDoc != NULL);


      CSeriesView* pView = new CSeriesView;
      RECT rectDefault;
      pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
             rectDefault, m_pMainWnd, AFX_IDW_PANE_FIRST + 1, NULL);

Thanks a lot, Peter
Question by:PeterTokeHedenAhlgren
    LVL 19

    Accepted Solution

    You can avoid MFC default document title in this way:

    1. ---------------  Remove the FWS_ADDTOTITLE style from the frame: -----------------------

    BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
          // TODO: Modify the Window class or styles here by modifying
          //  the CREATESTRUCT cs

                                  WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;

 &= ~FWS_ADDTOTITLE;  <------------------------ remove the style

          return CMDIChildWnd::PreCreateWindow(cs);

    2. --------------- Write the title you want: -------------------------------------------------

       GetParentFrame()->SetWindowText( "Your title" );    <---------- set the title

    Author Comment

    Hey alb66

    Does your suggestion mean that my document name is all right, so that it is actually the frame that messes up?
    LVL 19

    Expert Comment

    I just show you how to override the default frame title behavior...

    I don't know the reason why you do all the frame/doc/view creation by hand. My be because you need som parameters from your dialog.
    I think the simplest way is the following:

    void CMyApp::ImportTimeSeries()
      ImportExportTimeSeriesDlg OpenDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,ImportExportFilterStr);
      if( OpenDlg.DoModal() == IDOK )
        this->someValues = OpenDlg.someValues;
        OpenDocumentFile( OpenDlg.GetPathName() );
    BOOL CSeriesDoc::OnOpenDocument(LPCTSTR lpszPathName)
    	if (!CDocument::OnOpenDocument(lpszPathName))
    		return FALSE;
    	iSeries = timeseries<double>( theApp.someValues.... );
    	return TRUE;

    Open in new window


    Author Comment

    The reason I did all the things by hand was to be able to use different function like pNewSeriesDoc->Import(); and different overloads. I would also like to for instance open the same kind of document with data from a database. You can say it was a novices way of solving my problem!

    From your suggestion though, I can see that I could make a switch in BOOL CSeriesDoc::OnOpenDocument(LPCTSTR lpszPathName) that could react on the different ways I open and import in CMyApp.

    Thank you very much for your suggestion!

    All the best, Peter

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    maven archtype selection in eclipse 1 47
    countEvens challenge 2 47
    pre4 challenge 19 75
    Sed question 2 25
    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now