Solved

Changing the window title in MFC program

Posted on 1998-11-12
7
730 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 86
conditional code and condition difference 9 77
canBalance challenge 34 70
unix example issues 18 75
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 …
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

19 Experts available now in Live!

Get 1:1 Help Now