Solved

Changing the window title in MFC program

Posted on 1998-11-12
7
712 Views
Last Modified: 2013-11-20
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
Comment
Question by:leena_mary
7 Comments
 
LVL 1

Expert Comment

by:fkurucz
ID: 1324550
Hi leena_mary,

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

bye,
  feri

0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 1324551
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
 

Author Comment

by:leena_mary
ID: 1324552
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
ryane earned 50 total points
ID: 1324553
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1324554
I doubt if this will make the Untitled display will go!!
0
 

Author Comment

by:leena_mary
ID: 1324555
Many thanks to ryane, and fkurucz for his cryptic comment.
 
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1324556
Does this solution get rid of the Untitled display?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

17 Experts available now in Live!

Get 1:1 Help Now