MFC MDI document name

Posted on 2009-04-23
Medium Priority
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
  • 2
  • 2
LVL 19

Accepted Solution

alb66 earned 500 total points
ID: 24222491
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;

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

      return CMDIChildWnd::PreCreateWindow(cs);

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

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

Author Comment

ID: 24222618
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

ID: 24222852
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

ID: 24223056
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses
Course of the Month7 days, 10 hours left to enroll

607 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