當程式正在忙碌時, 讓使用者瞭解現狀的最好方法就是 ProgressBar
然而對我來說, 想要做的有質感又不想花時間雕畫面, 又是一件困難的事.
幸好 Paul 已經幫我們寫好了, 很簡單不要害怕!
長相如下:
(下載位址)
怎麼用呢? 很簡單 5 個步驟即可完成
CMacProgressCtrl m_progMac1;
Step 1: copy the files
MacProgressCtrl.cpp and MacProgressCtrl.h
into your project directory
Step 2: Add the files to your project
Step 3: In xxx.h, add the component's declaration
#include "MacProgressCtrl.h" // 加入元件的定義
Step 4: Initial the component
BOOL xxxDlg::OnInitDialog(){
CDialog::OnInitDialog();
m_progMac1.SetRange(0, 100); // 設定範圍
m_progMac1.SetStep(1); // 每次跳一
m_progMac1.SetPos(50); // 設定起始位置: 50
m_progMac1.SetColor(RGB(0, 255, 0)); // 設定顏色為綠色
// m_progMac1.SetIndeterminate();
return TRUE;
}
Step 5: Add DDX (注意: 請拉 ProgressBar 到 Dialog Resource 上)
*請設定 ProgressBar Resource ID = IDC_PROGRESS_MAC1
void CMacTest2Dlg::DoDataExchange(CDataExchange* pDX){
DDX_Control(pDX, IDC_PROGRESS_MAC1, m_progMac1);
}
================================
使用方式:
如果你把上面的元件放到 CMyProgressForm 這個 CDialog 中, 那麼在使用時可以使用 Modeless 的方式, 把 Dialog 建立起來.
CMyProgressForm *m_ProgressForm;
m_ProgressForm=new CMyProgressForm(); // 建立 Modeless Dialog
m_ProgressForm->Create(IDD_ProgressBar,this); // 選 Resource ID
m_ProgressForm->ShowWindow(SW_SHOW); // 顯示 Window
SW_HIDE
當然了, 你的高耗時程式應該要用一條特別的 thread來執行, 否則視窗根本不會繪圖.
Thread 的部分, 請參考下面網頁:
Enjoy
by Jing
沒有留言:
張貼留言