visual-studio-2010visual-studiomfcsdi

How to change the title/caption of MFC SDI documentless application


I can't find a working solution to change the title of my MFC SDI application. I don't use document/view. I need to change the title according to internal state of the applicaiton.

I've tried CMainFrame::SetWindowText from my main app module in InitInstance - with no luck.

I've tried to change CMainFrame::m_strTitle member variable and call OnUpdateFrameTitle(TRUE) after that - still no luck.

Inside OnTimer procedure - calling AfxGetMainWnd()->SetWindowText(_T("title from OnTimer")); - it does not work either.

What am I missing? That should be a common and simple task, shouldn't it?

EDIT: I'm sorry, it seems SetWindowText is working, just need to properly compile my app. That's all my fault.


Solution

  • Overwrite CMainFrame::PreCreateWindow. Clear the style FWS_ADDTOTITLE

    cs.style &= ~(LONG)FWS_ADDTOTITLE;          
    

    Now it should be possible the window caption in any way you like.

    The Default window caption is taken from the string resource with the ID AFX_IDS_APP_TITLE.