Solved

Changing the window title in MFC program

Posted on 1998-11-12
7
772 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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