views:

53

answers:

2

I am trying to show a progress bar while my process is going on...in my application there will be a situation where I gotta read files and manipulate them(it will take some time to complete)..want to display a progress bar during this operation..the particular function I am calling is an win 32 ...so if you check my code below ...I am able to display the progressbar but it doesnt show any progress..actually its not doing any further process...Please help me..thanks in advance

//my  function
int Myfunction(....)
{
 MSG msg;
 HWND dialog = CreateWindowEx(0,WC_DIALOG,L"Proccessing...",WS_OVERLAPPEDWINDOW|WS_VISIBLE,
     600,300,280,120,NULL,NULL,NULL,NULL);
 HWND pBar =  CreateWindowEx(NULL,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE,40,20,200, 20,
       dialog,(HMENU)IDD_PROGRESS,NULL,NULL);
 SendMessage(pBar,PBM_SETRANGE,0,MAKELPARAM(0,noOfFile));


  while(GetMessage(&msg,NULL,0,0))
  {
    TranslateMessage(&msg);
    Dispatch(&message);
  }

 HANDLE getHandle = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)SetFilesForOperation(...),
    NULL,NULL,0);

}


LPARAM SetFilesForOperation(...)       
{

 for(int index = 0;index < noOfFiles; index++)
 {


  *checkstate = *(checkState + index);
  if(*checkstate == -1)
  {
   *(getFiles+i) = new TCHAR[MAX_PATH];
   wcscpy(*(getFiles+i),*(dataFiles +index));
   i++;

  }
  else
  {
   (*tempDataFiles)->Add(*(dataFiles+index));
   *(checkState + localIndex) = *(checkState + index);
   localIndex++;
  }

  PostMessage(pBar,PBM_SETPOS,(WPARAM)index,0);
 }
}
A: 

F**k MFC, use Qt instead.

for this question, I will use this method:

use form designer to create a dialog, and use AfxBeginThread(someFunc, param) to create a thread.

and in someFunc, use SendMessage to tell the dialog about the progress.

sample here: http://www.tek-tips.com/faqs.cfm?fid=5162

linjunhalida
my question was about win 32 and not MFC...and i think its not the right answer that u gave..anyways thanks for ur reply
kiddo
+2  A: 

I suspect the problem is that you're creating the thread after your app exits - if you move the call to CreateThread above the message pump it may work better.

Larry Osterman
only if it shows the progress bar..it (thread) can process about it...if its not showing its off no use of displayin the progress bar after finishing the task
kiddo