1)添加字符串资源:
打开资源视图下的String Table并添加字符串资源,如下图:
2)在对话框类头文件中进行状态栏对象的定义:CStatusBar m_wndStatusBar;
3)定义窗格数组:
static UINT indicators[]={ ID_INDICATOR_THREADNUM, ID_INDICATOR_FILENUM, ID_INDICATOR_TIME};4)在对话框类的初始化函数 OnInitDialog() 中进行状态栏的创建:if (!m_wndStatusBar.CreateEx(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar/n"); return -1; // fail to create } CRect rect; GetClientRect(&rect); m_wndStatusBar.SetPaneInfo(0, ID_INDICATOR_THREADNUM, SBPS_NORMAL, rect.Width()/3); m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_FILENUM, SBPS_STRETCH , rect.Width()/3); m_wndStatusBar.SetPaneInfo(2, ID_INDICATOR_TIME, SBPS_STRETCH , rect.Width()/3); RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, AFX_IDW_CONTROLBAR_FIRST);5)启动定时器:SetTimer(3, 50, NULL),并响应对话框类的 WM_TIMER 消息,在 OnTimer 中添加如下代码:void CFileSearchToolDlg::OnTimer(UINT_PTR nIDEvent){ switch (nIDEvent) { case 1: break; case 2: break; case 3: if (!g_bStop) { CString strThreadNum,strFileNum,strTime; GetLocalTime(&T2); DiffSecond = GetDiffSeconds(T1, T2); strThreadNum.Format(_T("当前线程数量 %d "),g_nThreadNum); strFileNum.Format(_T("当前文件数量 %d "),g_nFileNum); strTime.Format(_T("遍历持续时间 %d 秒"),DiffSecond); m_wndStatusBar.SetPaneText(0,strThreadNum); m_wndStatusBar.SetPaneText(1,strFileNum); m_wndStatusBar.SetPaneText(2,strTime); } break; } CDialogEx::OnTimer(nIDEvent);}6)重载对话框类的 OnCancel() 函数,进行定时器的销毁工作:KillTimer(3);
新闻热点
疑难解答