我有一个方法负责将内存中的immes保存到硬盘驱动器,最后会返回一个布尔值。现在我已经创建了一个进度条。但我真的不知道我怎么能以这种方法为进度条连接这个方法,只要该方法保存进度得到更新并显示蓝色条。这是我的代码:
switch(_formatIndex){
case 0:
save.saveImages(_MatVector,0, path);
int pb_pos;pb_pos= SendMessage(_progressBar, PBM_GETPOS, 0, 0);
while(pb_pos<100){
SendMessage(_progressBar, PBM_SETPOS, pb_pos, 0);
pb_pos++;
}
break;
case 1:
save.saveImages(_MatVector,1, path);
break;
}
答案 0 :(得分:5)
您需要知道保存了多少文件,然后在保存每个文件后递增进度条,而不是一次全部。例如:
SendMessage(_progressBar, PBM_SETRANGE32, 0, NumberOfFiles);
SendMessage(_progressBar, PBM_SETSTEP, 1, 0);
SendMessage(_progressBar, PBM_SETPOS, 0, 0);
for (int i = 0; i < NumberOfFiles; ++i)
{
...
save.saveImages(_MatVector, _formatIndex, path);
SendMessage(_progressBar, PBM_STEPIT, 0, 0);
...
}
可替换地:
SendMessage(_progressBar, PBM_SETRANGE, 0, 100);
SendMessage(_progressBar, PBM_SETPOS, 0, 0);
for (int i = 0; i < NumberOfFiles; ++i)
{
...
save.saveImages(_MatVector, _formatIndex, path);
SendMessage(_progressBar, PBM_SETPOS, (i * 100) / NumberOfFiles, 0);
...
}
答案 1 :(得分:0)
SendMessage(GetDlgItem(hAutoParent,IDC_PROGRESS1),PBM_SETRANGE,0, MAKELPARAM(0,10 ));
SendMessage(GetDlgItem(hAutoParent,IDC_PROGRESS1),PBM_SETBARCOLOR,0,(LPARAM)colorResult3);
SendMessage(GetDlgItem(hAutoParent,IDC_PROGRESS1),PBM_SETBKCOLOR,0,(LPARAM)colorResult2);
SendMessage(GetDlgItem(hAutoParent,IDC_PROGRESS1),PBM_SETPOS,0,0);
int iProgressPosition=0;//Intially global variable
SendMessage(GetDlgItem(hAutoParent,IDC_PROGRESS1),PBM_SETPOS, iProgessPosition,0);
//incremented global varibale in loop is equal to 10(setrange 10)
iProgressPosition++;