我建立了一个基于对话框的mfc,现在需要加一个状态栏,并且状态栏要随主窗口变化而变化,例如主窗口最大化时,状态栏在底部,则主窗口变化时,状态栏始终在主窗口底部....希望各位兄弟姐妹帮帮忙,贴个代码,不要代码地址

解决方案 »

  1.   

    .H中:
    class CUSDLG : public CDialog
    {public:
    CStatusBar m_dlgStatusBar;
            //... ...
    }
    .CPP中:
    static UINT indicators[] =
    {
    IDS_panel1,  //在StringTalbe里面添加
    IDS_panel2,
    ID_SEPARATOR, 
    ID_SEPARATOR,
    ID_SEPARATOR,
    };BOOL CUSDLG::OnInitDialog()
    {
            //... ...
    if (!m_dlgStatusBar.Create(this) || !m_dlgStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)) )
    {
    TRACE0("Failed to create status bar\n");
    return -1;
    } m_dlgStatusBar.SetPaneInfo(0,IDS_panel1,SBPS_NORMAL,30); 
    m_dlgStatusBar.SetPaneInfo(1,IDS_panel2,SBPS_NORMAL,30);

    m_dlgStatusBar.SetPaneInfo(3,ID_SEPARATOR,0,35); //设置新增窗格1的宽度
    m_dlgStatusBar.SetPaneInfo(4,ID_SEPARATOR,0,50); //设置新增窗格2的宽度 CRect rect;
    GetClientRect(rect); //获得客户区的大小
    m_dlgStatusBar.MoveWindow(0, rect.bottom-20, rect.right, 20);
            //... ...
    }void CUSDLG::OnSize(UINT nType, int cx, int cy) //主要是这个函数里面要对状态条位置进行改变。
    {
    if( this->m_hWnd && m_dlgStatusBar.m_hWnd )
    {
    CRect rect;
    GetClientRect(rect); //获得客户区的大小
    m_dlgStatusBar.MoveWindow(0, rect.bottom-20, rect.right, 20);
    }
    CDialog::OnSize(nType, cx, cy);
    }