刘华世的官方博客

C++语言 在状态栏中显示进度条

BOOL CProgressStatusBarDlg::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,90); //设置面板宽度
    }
    //设置面板文本
    m_StatusBar.SetPaneText(0,"当前用户:");
    m_StatusBar.SetPaneText(1,"TM");
    m_StatusBar.SetPaneText(2,"当前状态:");
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); //显示状态栏
    RECT m_rect;
    m_StatusBar.GetItemRect(3,&m_rect); //获取第四个面板的区域    
    m_Progress.SetParent(&m_StatusBar); //设置进度条的父窗口为状态栏
    m_Progress.MoveWindow(&m_rect);     //设置进度条显示的位置
    m_Progress.ShowWindow(SW_SHOW);     //显示进度条控件
    m_Progress.SetRange(0,30);          //设置进度条范围
    m_Progress.SetPos(15);              //设置进度条当前位置

    return TRUE;  // return TRUE  unless you set the focus to a control
}

调用Create方法创建栏窗口, 调用SetIndicators方法向状态栏窗口中添加面板,调用SetPanelInfo方法设置面板的宽度,调用SetPaneText方法设置面板的显示文本,调用RepositionBars方法显示状态栏.

调用GetItemRect方法获得要显示控件的面板区域.

通过MoveWindow函数和ShowWindow函数, 移动控件到获得的面板区域中,并显示控件.

posted @ 2012-11-27 13:50  pythonschool  阅读(990)  评论(0编辑  收藏  举报
刘华世的官方博客