1,建立单文档工程后,在资源栏的 String Table 的成员中添加显示名:
IDS_Status
IDS_TimeCost
IDS_ItemsScanned
2,修改 MainFrm.cpp 中的 indicators 定义:
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
IDS_Status,
IDS_TimeCost,
IDS_ItemsScanned,
// ID_INDICATOR_CAPS,
// ID_INDICATOR_NUM,
// ID_INDICATOR_SCRL,
};
3,在 CMainFrame::OnCreate() 中创建代码之后添加设置代码:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar/n");
return -1; // fail to create
}
// 设置状态栏的信息显示位置
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(IDS_Status), IDS_Status, SBPS_NORMAL, 100);
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(IDS_TimeCost), IDS_TimeCost, SBPS_NORMAL, 150);
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(IDS_ItemsScanned), IDS_ItemsScanned, SBPS_NORMAL, 150);
return 0;
}
4,在消息处理函数中修改显示的值串:
LRESULT CMainFrame::OnMSGGotFileStatus(WPARAM wParam, LPARAM lParam)
{
CSD_FileScannerView* pView = (CSD_FileScannerView*)GetActiveView();
pView->OnMSGGotFileStatus(wParam, lParam);
CFileStatus fileStatus(*(CFileStatus*)lParam);
m_wndStatusBar.SetPaneText(0, fileStatus.m_szFullName);
CString str;
str.Format(_T("Time Cost: %u.%03d Sec")
, (GetTickCount() - m_dwStartTick)/1000
, (GetTickCount() - m_dwStartTick)%1000
);
int iIndex = m_wndStatusBar.CommandToIndex(IDS_TimeCost);
m_wndStatusBar.SetPaneText(iIndex, str);
return 0;
}