Solved

Changing the window title in MFC program

Posted on 1998-11-12
7
749 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 99
fizzArray  challenge 1 83
pre4 challenge 19 100
My project did see openJDK that I installed. What could be the problem 7 143
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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