1)添加字符串資源:
打開資源視圖下的String Table并添加字符串資源,如下圖:
2)在對(duì)話框類頭文件中進(jìn)行狀態(tài)欄對(duì)象的定義:CStatusBar m_wndStatusBar;
3)定義窗格數(shù)組:
static UINT indicators[]={ ID_INDICATOR_THREADNUM, ID_INDICATOR_FILENUM, ID_INDICATOR_TIME};4)在對(duì)話框類的初始化函數(shù) OnInitDialog() 中進(jìn)行狀態(tài)欄的創(chuàng)建: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)啟動(dòng)定時(shí)器:SetTimer(3, 50, NULL),并響應(yīng)對(duì)話框類的 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āng)前線程數(shù)量 %d "),g_nThreadNum); strFileNum.Format(_T("當(dāng)前文件數(shù)量 %d "),g_nFileNum); strTime.Format(_T("遍歷持續(xù)時(shí)間 %d 秒"),DiffSecond); m_wndStatusBar.SetPaneText(0,strThreadNum); m_wndStatusBar.SetPaneText(1,strFileNum); m_wndStatusBar.SetPaneText(2,strTime); } break; } CDialogEx::OnTimer(nIDEvent);}6)重載對(duì)話框類的 OnCancel() 函數(shù),進(jìn)行定時(shí)器的銷毀工作:KillTimer(3);
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注