0
votes

I have an MFC application using MDI, something similar to the MFC Scribble example/tutorial. When the child window is maximized, the caption/title of the main frame window is automatically adjusted so that the title of the child window is appended, like "Scribble - [Scribb1]". When the title of the child window is very long, it is truncated. The length of whole caption seems to be limited to about 160 characters. Is there a way to increase this limit and show more characters? I guess overriding WM_NCPAINT to redraw the caption is one way, but prefer other simple solution if there is one. I've tried overriding OnUpdateFrameTitle() and it doesn't seem to work for the whole combined caption.

2

2 Answers

1
votes

Overriding OnUpdateFrameTitle and calling own implementation of the UpdateFrameTitleForDocument won’t work. Amit already tried your solution before even posting.

This is not even implemented by MFC. MDI window is not introduced by MFC. MDI frame window existed since I remember as part of the Windows OS.

Default MFC implementation down in the bowels of the MFC calls special MDI window procedure defined as DefFrameProc, as required.

Windows implementation for some mysterious reason truncate window text (displayed on the title bar of the MDI frame) to 160 characters, including terminating 0 when processing WM_SETTEXT message. This is probably the remnant of the old computers that did not have much memory to waste and all buffers sizes were kept to a minimum.

This is probably the remnant of the old computers that did not have much memory to waste and all buffers sizes were kept to a minimum and file names were 8.3 total 12 characters.

To fulfill your requirements and display full text you would have to make some changes.

Fortunately, I found really easy way of changing this behavior, in agreement with my MEMC requirement.

In your main frame class override DefWindowProcand change the code as follows:

LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    if(WM_SETTEXT == message)
    {
        // if set text (called from UpdateFrameTitleForDocument)
        // do not call DefWindowProc
        return CWnd::DefWindowProc(message, wParam, lParam);
    }

    // otherwise call DefWindowProc that in turn calls DefFrameProc
    return CMDIFrameWndEx::DefWindowProc(message, wParam, lParam);
}

Now build and run.

This works for classinc and Visual studio styles of the MFC app.

1
votes

Have a look at CFrameWnd::OnUpdateFrameTitle which internally is calling CFrameWnd::UpdateFrameTitleForDocument() method. It does the magic. It is a virtual method. You can override OnUpdateFrameTitle in your CMainFrm class and set the window title as desired.

If you did not know, MFC library is provided totally with the source. The CFrameWnd source is in winfrm.cpp (search for this file, and you will learn where the source for MFC on your PC)