When maximize window, the title disappear?

Ken 46 Reputation points
2020-12-28T13:47:29.843+00:00

Hi, everyone.
I created a MFC application with office style(a style with ribbons). I set the title by the code following:
SetTitle(_T("This is the new title"));
RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
The code works well. However, when I maximize the window by pressing the maximize button in the upper right corner, the title disappear. This is not what I want. How can I make the title appear again?
51613-1.png

window before maximizing shows the title.
51594-2.png

window after maximizing doesn't show the title.

I'd appreciate it if you could give me some advice

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,683 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 44,931 Reputation points
    2020-12-28T14:21:53.053+00:00

    If I remember correctly what is happening is that MFC is drawing the text in the window caption for a maximized window using white. Windows 10 uses white for the caption bar. So white text on a white background is not visible.

    One way to solve the problem is to change the way that MFC draws the caption text for the maximized window. One way to do this when using the MFC Ribbon and the related CMFCVisualManager derived classes is to roll your own and override a virtual method.

    For example -

    MyVisualManagerOffice2007.h -

    #pragma once  
      
    // CMyVisualManagerOffice2007 command target  
      
    class CMyVisualManagerOffice2007 : public CMFCVisualManagerOffice2007  
    {  
        DECLARE_DYNCREATE(CMyVisualManagerOffice2007);  
      
    public:  
        CMyVisualManagerOffice2007();  
        virtual ~CMyVisualManagerOffice2007();  
        BOOL DrawTextOnGlass(  
            CDC* pDC,  
            CString strText,  
            CRect rect,  
            DWORD dwFlags,  
            int nGlowSize = 0,  
            COLORREF clrText = (COLORREF)-1) override;  
    };  
      
      
      
    

    MyVisualManagerOffice2007.cpp -

    // MyVisualManagerOffice2007.cpp : implementation file  
    //  
      
    #include "stdafx.h"  
    #include "MyVisualManagerOffice2007.h"  
      
    // CMyVisualManagerOffice2007  
      
    IMPLEMENT_DYNCREATE(CMyVisualManagerOffice2007, CMFCVisualManagerOffice2007);  
      
    CMyVisualManagerOffice2007::CMyVisualManagerOffice2007()  
    {  
    }  
      
    CMyVisualManagerOffice2007::~CMyVisualManagerOffice2007()  
    {  
    }  
      
    BOOL CMyVisualManagerOffice2007::DrawTextOnGlass(CDC * pDC, CString strText, CRect rect, DWORD dwFlags, int nGlowSize, COLORREF clrText)  
    {  
        COLORREF clr = clrText != RGB(255, 255, 255) ? clrText : RGB(255, 0, 0);  
        return CMFCVisualManagerOffice2007::DrawTextOnGlass( pDC, strText, rect, dwFlags, nGlowSize, clr);  
    }  
      
      
    

    Edit MainFrame.cpp OnApplicationLook function to use the CMyVisualManagerOffice2007 class -

            switch (theApp.m_nAppLook)  
            {  
            case ID_VIEW_APPLOOK_OFF_2007_BLUE:  
                CMyVisualManagerOffice2007::SetStyle(CMyVisualManagerOffice2007::Office2007_LunaBlue);  
                break;  
      
            case ID_VIEW_APPLOOK_OFF_2007_BLACK:  
                CMyVisualManagerOffice2007::SetStyle(CMyVisualManagerOffice2007::Office2007_ObsidianBlack);  
                break;  
      
            case ID_VIEW_APPLOOK_OFF_2007_SILVER:  
                CMyVisualManagerOffice2007::SetStyle(CMyVisualManagerOffice2007::Office2007_Silver);  
                break;  
      
            case ID_VIEW_APPLOOK_OFF_2007_AQUA:  
                CMyVisualManagerOffice2007::SetStyle(CMyVisualManagerOffice2007::Office2007_Aqua);  
                break;  
            }  
      
            CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMyVisualManagerOffice2007));  
      
    

    Above changes will cause the caption text to be drawn in red when the window is maximized.

    Not maximized -

    51567-notmax.png

    maximized -

    51642-max.png


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.