• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1119
  • Last Modified:

Changing the window title in MFC program

Hi,
I have created an MFC project based on the "FORMVIEW" class.

How do I change the title of the MainFrame Window which is
now appearing as "Untitled-[application name]"?

I am new to Visual C++. Please help.....Thanks......
0
leena_mary
Asked:
leena_mary
1 Solution
 
fkuruczCommented:
Hi leena_mary,

you may call the CWnd member Function
   SetWindowText("newtitle");

bye,
  feri

0
 
GGRUNDYCommented:
You could as fkurucz suggests use SetWindowText but the MFC framework being the smarty pants that it is, will just as likely overwrite your wishes as soon as you look at it sideways. If you want to go with the flow it will be a case of using the resource editor to change the application name in the string table.

IDR_MAINFRAME <windowTitle>\n<docName>\n<fileNewName>\n<filterName>\n
              <filterExt>\n<regFileTypeID>\n<regFileTypeName>\n
              <filterMacExt(filterWinExt)>\n
              <filterMacName(filterWinName)>

The document document title will change automatically when you save the document but you could also call the CDocument::SetTitle function yourself.

      
If you poke about in the source code you will see the sort of things that it considers when
setting the mainframe title.

void CFrameWnd::UpdateFrameTitleForDocument(LPCTSTR lpszDocName)
{
      // copy first part of title loaded at time of frame creation
      TCHAR szText[256+_MAX_PATH];

      if (GetStyle() & FWS_PREFIXTITLE)
      {
            szText[0] = '\0';   // start with nothing

            // get name of currently active view
            if (lpszDocName != NULL)
            {
                  lstrcpy(szText, lpszDocName);
                  // add current window # if needed
                  if (m_nWindow > 0)
                        wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);
                  lstrcat(szText, _T(" - "));
            }
            lstrcat(szText, m_strTitle);
      }
      else
      {
            // get name of currently active view
            lstrcpy(szText, m_strTitle);
            if (lpszDocName != NULL)
            {
                  lstrcat(szText, _T(" - "));
                  lstrcat(szText, lpszDocName);
                  // add current window # if needed
                  if (m_nWindow > 0)
                        wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);
            }
      }

      // set title if changed, but don't remove completely
      // Note: will be excessive for MDI Frame with maximized child
      AfxSetWindowText(m_hWnd, szText);
}

If you really want to override the framework you are probably going have to add a
WM_SETTEXT message handler to your mainframe which doesn't pass the frameworks
multifarious SetWindowText messages on to the default message processor.

Rigt about now I bet "Untitled-[application name]" is looking like a pretty good title for
your window.

Cheers Greg
0
 
leena_maryAuthor Commented:
Hi,
Changing IDR_MAINFRAME in the resource file is of no help.
It still shows "Untitled - [Changed name]".

Your other suggestion seems to be too lengthy for a pretty short
problem. So I did not try that.

Is there any simple way of changing the Mainframe Window title???  

Anyway thanks for your concern.

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ryaneCommented:
Add a call to CWnd::SetWindowText for the main frame window object near the end of the InitInstance function in the main source file...

    // The one and only window has been initialized, so show and
    // update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();

    --> m_pMainWnd->SetWindowText("New Title Goes Here"); <--

    return TRUE;
}

Under the ClassView tab, this will be located under the C<YOUR APP NAME>App.  You should see a member function called InitInstance.  Locate the above in this function and add the line with the --> <-- (minus the --> <-- of course :)

-ryane
0
 
pagladasuCommented:
I doubt if this will make the Untitled display will go!!
0
 
leena_maryAuthor Commented:
Many thanks to ryane, and fkurucz for his cryptic comment.
 
0
 
pagladasuCommented:
Does this solution get rid of the Untitled display?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now