A Popup Progress Window
一个包含bar和取消而且不需要资源弹出窗口
1.构造函数
CProgressWnd(); CProgressWnd(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE); BOOL Create(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE);
参数说明:
pParent//父窗口 strTitle//窗口标题 bSmooth//是否平滑
2.方法属性
BOOL GoModal(LPCTSTR strTitle = _T("Progress"), BOOL bSmooth=FALSE); // Make window modal 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 SetRange(int nLower, int nUpper, int nStep = 1); // Set min, max and step size void Hide(); // Hide the window void Show(); // Show the window void Clear(); // Clear the text and reset the // progress bar void SetText(LPCTSTR fmt, ...); // Set the text in the text area BOOL Cancelled() // Has the cancel button been pressed? void SetWindowSize(int nNumTextLines, int nWindowWidth = 390); // Sets the size of the window // according to the number of text // lines specifed and the // desired window size in pixels. void PeekAndPump(BOOL bCancelOnESCkey = TRUE); // Message pumping, with options of // allowing Cancel on ESC key.
SetWindowSize()默认显示四行
PeekAndPump()防止消息阻塞,在走进度过程中,相关操作可以继续执行,如esc取消,鼠标点击等等
3例子
通过GoModal()显示
CProgressWnd wndProgress(this, "Progress"); // wndProgress.GoModal(); // Call this if you want a modal window wndProgress.SetRange(0,5000); wndProgress.SetText("Processing..."); for (int i = 0; i < 5000; i++) { wndProgress.StepIt(); wndProgress.PeekAndPump(); if (wndProgress.Cancelled()) { MessageBox("Progress Cancelled"); break; } }
或者Create()
CProgressWnd wndProgress; if (!wndProgress.Create(this, "Progress")) return; wndProgress.SetRange(0,5000); wndProgress.SetText("Processing...");
源代码链接地址:http://download.csdn.net/detail/wuyuan2011woaini/9594242
天道酬勤 循序渐进 技压群雄
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步