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);
}

常记溪亭日暮,沉醉不知归路。兴尽晚回舟,误入藕花深处。争渡,争渡,惊起一滩鸥鹭。

昨夜雨疏风骤,浓睡不消残酒。试问卷帘人,却道海棠依旧。知否?知否?应是绿肥红瘦。
原文地址:https://www.cnblogs.com/htj10/p/11939009.html