C++语言 创建状态栏

BOOL CCreateStatusBarDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    // TODO: Add extra initialization here
    UINT array[4];
    for(int i=0;i<4;i++)
    {
        array[i] = 1001 + i;
    }
    m_StatusBar.Create(this); //创建状态栏窗口
    m_StatusBar.SetIndicators(array,sizeof(array)/sizeof(UINT)); //添加面板
    for(int n=0;n<4;n++)
    {
        m_StatusBar.SetPaneInfo(n,array[n],0,100); //设置面板宽度
    }
    CTime time = CTime::GetCurrentTime();
    m_StatusBar.SetPaneText(0,"当前用户:");//设置面板文本
    m_StatusBar.SetPaneText(1,"TM");
    m_StatusBar.SetPaneText(2,"当前日期:");
    m_StatusBar.SetPaneText(3,time.Format("%Y-%m-%d"));
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
    return TRUE;  // return TRUE  unless you set the focus to a control
}

//创建一个基于对话框的应用程序,将对话框的Caption属性修改为"创建状态栏".
//在对话框头文件中声明一个CStatusBar类变量m_StatusBar.
###如果程序中同时具有工具栏和状态栏,只需要调用一次 RepositionBars 函数.

原文地址:https://www.cnblogs.com/pythonschool/p/2789133.html