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);
新聞熱點
疑難解答