Showing progress bar in a status bar pane
在工具卡显示进度条,原文链接:http://www.codeproject.com/Articles/35/Showing-progress-bar-in-a-status-bar-pane
1.构造函数
CProgressBar(); CProgressBar(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0); BOOL Create(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0);
参数说明:
strMessage//bar字符串 nSize//占比 MaxValue//bar最大值(0~MaxValue) bSmooth//是否平滑 nPane//状态栏第几子项
2.方法函数
BOOL Success() // Construction successful? COLORREF SetBarColour(COLORREF clrBar); // Set Bar colour, returns previous COLORREF SetBkColour(COLORREF clrBar); // Set background colour, returns previous int SetPos(int nPos); // Same as CProgressCtrl int OffsetPos(int nPos); // Same as CProgressCtrl int SetStep(int nStep); // Same as CProgressCtrl int StepIt(); // Same as CProgressCtrl void Clear(); // Clear the status bar void SetRange(int nLower, int nUpper, int nStep = 1); // Set min, max and step size void SetText(LPCTSTR strMessage); // Set the message void SetSize(int nSize); // Set the bar size
3.应用
CProgressBar Bar("Testing", 40, 1000); for (int i = 0; i < 1000; i++) { // perform operation Bar.StepIt(); }
CProgressBar bar; bar.Create("Processing", 40, 1000); for (int i = 0; i < 1000; i++) { // perform operation bar.StepIt(); } bar.SetText("Writing"); for (int i = 0; i < 1000; i++) { // perform operation bar.StepIt(); PeekAndPump(); // Message pump } bar.Clear();
PeekAndPump()函数的作用是进行,消息循环,使之进度条走时,可进行操作响应,如最大最小化等等
BOOL PeekAndPump() { static MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) { ::PostQuitMessage(0); return FALSE; } } return TRUE; }
运行结果如下:
代码下载地址:http://download.csdn.net/detail/wuyuan2011woaini/9595419
天道酬勤 循序渐进 技压群雄