How to show the progressbar using threading functionality in win32?

Posted by kiddo on Stack Overflow See other posts from Stack Overflow or by kiddo
Published on 2010-04-27T10:26:20Z Indexed on 2010/04/27 11:03 UTC
Read the original article Hit count: 318

Filed under:
|
|

In my application I have a simple module were I will read files for some process that will take few seconds..so I thought of displaying a progress bar(using worker thread) while the files are in progress.I have created a thread (code shown below) and also I designed a dialog window with progress control.I used the function MyThreadFunction below to display the progressbar but it just shows only one time and disappears,I am not sure how to make it work.I tried my best inspite of the fact that I am new to threading.Please help me with this friends.

reading files
void ReadMyFiles()
{

   for(int i = 0; i < fileCount ; fileCount++)
    {   
    CWinThread* myThread = AfxBeginThread((AFX_THREADPROC)MyThreadFunction,NULL);
    tempState = *(checkState + index);
    if(tempCheckState == NOCHECKBOX)
    {
        //my operations
    }
    else//CHECKED or UNCHECKED
    {
        //myoperation
    }
    myThread->PostThreadMessage(WM_QUIT,NULL,NULL);
    }
}

thread functions
UINT MyThreadFunction(LPARAM lparam)
{
    HWND dialogWnd = CreateWindowEx(0,WC_DIALOG,L"Proccessing...",WS_OVERLAPPEDWINDOW|WS_VISIBLE,
                    600,300,280,120,NULL,NULL,NULL,NULL);
    HWND pBarWnd =  CreateWindowEx(NULL,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE|PBS_MARQUEE,40,20,200,20,
                            dialogWnd,(HMENU)IDD_PROGRESS,NULL,NULL);

    MSG msg;

    PostMessage( pBarWnd, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
    PostMessage(pBarWnd,PBM_SETPOS,0,0);
    while(PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
    {
        if(msg.message == WM_QUIT)
        {
            DestroyWindow(dialogWnd);
            return 1;
        }
        AfxGetThread()->PumpMessage();
        Sleep(40);
    }
    return 1;


}

© Stack Overflow or respective owner

Related posts about threading

Related posts about win32