MFC中SDI设置状态栏显示时间

在 MainFrm.cpp 中

static UINT indicators[] =
{
    ID_SEPARATOR,           // 状态行指示器
    IDS_POS,
    IDS_TIMER, //添加显示时间的指示器
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
};

//在OnCreate()中
SetTimer(1, 1000, NULL);


void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
    // TODO:  在此添加消息处理程序代码和/或调用默认值
    COleDateTime t = COleDateTime::GetCurrentTime();
    CString str = t.Format(L"%H:%M:%S");
    CClientDC dc(this);
    CSize sz = dc.GetTextExtent(str);
    int nIndex = m_wndStatusBar.CommandToIndex(IDS_TIMER);
    m_wndStatusBar.SetPaneInfo(nIndex, IDS_TIMER, SBPS_NORMAL, sz.cx);
    m_wndStatusBar.SetPaneText(nIndex, str);

    CFrameWnd::OnTimer(nIDEvent);
}


//设置鼠标的坐标,在view.cpp
void CSDIView::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO:  在此添加消息处理程序代码和/或调用默认值
    CString str;
    str.Format(L"(%d, %d)", point.x, point.y);
    CStatusBar* pSB = (CStatusBar*)((CMainFrame*)GetParent())->GetMessageBar();
    int nIndex = pSB->CommandToIndex(IDS_POS);
    CClientDC dc(this);
    CSize sz = dc.GetTextExtent(str);
    pSB->SetPaneInfo(nIndex, IDS_POS, SBPS_NORMAL, sz.cx);
    pSB->SetPaneText(nIndex, str);
    //GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR)->SetWindowText(str);
    //((CMainFrame*)GetParent())->SetMessageText(str);
    //pSB->SetWindowText(str);

    CView::OnMouseMove(nFlags, point);
}

 

posted @ 2019-11-26 22:46  htj10  阅读(232)  评论(0编辑  收藏  举报
TOP