user261002
user261002

Reputation: 2252

win32 api update the progressbar to a method

I have a method which is responsible of saving immes from memory to the harddrive and at the end will return a boolean value. now I have created a progress bar. but I really dont know how I can conenct the progress bar to this method in a way that as far as the method is saving the progress get updated and show the blue bar. here is my code :

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;
        }   

Upvotes: 1

Views: 2609

Answers (2)

sankar
sankar

Reputation: 82

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++;

Upvotes: 1

Remy Lebeau
Remy Lebeau

Reputation: 596307

You need to know how many files are being saved, and then increment the progress bar after each file is saved, not all at once. For example:

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); 
    ...
}   

Alternatively:

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); 
    ...
}   

Upvotes: 6

Related Questions