Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFC application title

Tags:

mfc

I am creating a simple clock application using MFC. My application title appears as follows : "CLOCK - [CLOCK1]". How do I reset it to simply "CLOCK"? FYI, I have enabled the Document-View architecture.

like image 818
Gumbly jr. Avatar asked Apr 25 '14 21:04

Gumbly jr.


2 Answers

Put in this override of the MFC title:

void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
SetWindowText(L"CLOCK");
}
like image 84
ScottMcP-MVP Avatar answered Sep 30 '22 10:09

ScottMcP-MVP


There's an answer here, but I feel that the following solution is more "proper".

In addition to overriding CMainFrame::OnUpdateFrameTitle(), you also need to override CMainFrame::PreCreateWindow() as below:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{   cs.style &= ~FWS_ADDTOTITLE;
    return CFrameWndEx::PreCreateWindow(cs); // replace CFrameWndEx by CFrameWnd if
}                                            // your CMainFrame is based on CFrameWnd

A note: it is better to use AfxSetWindowText(m_hWnd, _T("foo")) instead of SetWindowText(_T("foo")) to avoid excessive flicker, it checks that the text is different before setting the window text.

like image 30
Edward Clements Avatar answered Sep 30 '22 10:09

Edward Clements