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.
Put in this override of the MFC title:
void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
SetWindowText(L"CLOCK");
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With