MFC status bar programming in VS environment (set status bar size, font size, background color and text color, etc.)

effect needed

1. My new project is an mfc multi-document with ribbon, and the result is CMFCRibbonStatusBar m_wndStatusBar in the header file of mainfrm; later I found that I can't use many functions before the status bar, so first check the declaration of the status bar variable

     Need to be changed to CMFCStatusBar m_wndStatusBar;

2. In the resource view, insert three characters into the String Table

    

3. In order to change the text color and background color of the status bar, you need to add oncommand

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
      // Added ON_COMMAND_RANGE, the first parameter is the start value, the second parameter is the end value 
    ON_COMMAND_RANGE(IDS_STATUS_PANE1,IDS_STATUS_PANE3,NULL)
END_MESSAGE_MAP()

 

3. Then insert the code in the onCreate function of the mainframe

    static UINT indicatros[]=
    {
        IDS_STATUS_PANE1,
        IDS_STATUS_PANE2,
        IDS_STATUS_PANE3,
    };
    if (!m_wndStatusBar.Create(this)||!m_wndStatusBar.SetIndicators(indicatros,sizeof(indicatros)/sizeof(UINT)))
    {
        TRACE0( " Failed to create the status bar\n " );
         return - 1 ;       // Failed to create 
    }
     // Set the font of the status bar 
    CFont* fontstatus= new CFont;
    fontstatus->CreateFont(15,0,0,0,FW_BOLD,FALSE,FALSE,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH |FF_MODERN,_T("宋体"));
    m_wndStatusBar.SetFont(fontstatus);
    // Get the status bar index 
    int a = m_wndStatusBar.CommandToIndex(IDS_STATUS_PANE1);   //
     int b = m_wndStatusBar.CommandToIndex(IDS_STATUS_PANE2);   //
     int c = m_wndStatusBar.CommandToIndex(IDS_STATUS_PANE3);   // 
    // Set the pane width 
    m_wndStatusBar .SetPaneWidth(a, 250 );
    m_wndStatusBar.SetPaneWidth(b,180);
    m_wndStatusBar.SetPaneWidth(c, 180 );
     // Set background color
     // m_wndStatusBar.SetPaneBackgroundColor(vecIndex,RGB(255,255,255));
     // m_wndStatusBar.SetPaneBackgroundColor(posIndex,RGB(255,255,255));
     // m_wndStatusBar.SetPaneBackgroundColor(valIndex, RGB(0,32,64));
     // Set the text color 
    m_wndStatusBar.SetPaneTextColor(a, RGB( 0 , 0 , 0 ));
    m_wndStatusBar.SetPaneTextColor(b, RGB(0, 0, 0));
    m_wndStatusBar.SetPaneTextColor(c, RGB( 0 , 0 , 0 ));
     // Open the timer and display the time in real time 
    SetTimer( 1 , 1000 ,NULL);

4. Change the part of the date on the panel in OnTimer

void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: add message handler code here and/or call default
     // populate measurement time 
    COleDateTime Now;
    Now=COleDateTime::GetCurrentTime();
    WORD y,m,d,h,i,s;
    CString str;
    y=Now.GetYear();
    m=Now.GetMonth();
    d=Now.GetDay();
    h=Now.GetHour();
    i=Now.GetMinute();
    s=Now.GetSecond();
    str.Format("%d年%d月%d日%d:%d:%d",y,m,d,h,i,s);
        m_wndStatusBar.SetPaneText(0,str);
    CMDIFrameWndEx::OnTimer(nIDEvent);
}

So far, most of the functions about the status bar have been implemented.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324755859&siteId=291194637