Q:

Problem displaying the Message box in MFC

I have a simple MFC program which displays the progressbar..I used the below code to display the progress bar..
HWND dialogHandle = CreateWindowEx(0,WC_DIALOG,L"Proccessing...",WS_OVERLAPPEDWINDOW|WS_VISIBLE,
                    600,300,280,120,NULL,NULL,NULL,NULL);
HWND progressBarHandle =  CreateWindowEx(NULL,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE|PBS_MARQUEE,40,20,200,20,
            dialogHandle,(HMENU)IDD_PROGRESS,NULL,NULL);

while(FALSE == testResult)
    {
        MSG msg;
         SendMessage(progressBarHandle, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
        SendMessage(progressBarHandle,PBM_SETPOS,0,0);
        ShowWindow(progressBarHandle,SW_SHOW);
        Sleep(50);
             if(TRUE == myCondition)//myCondition is a bool variable which is decalred globally
            {

                DestroyWindow(dialogHandle);
                 AfxMessageBox(L"Test Success");
             }
        }

when I execute the above code..the message box displays only after a mouseover event.like if I move the mouse the message box will display if not it will not display until i move the mouse.
And also while the progressbar is running if I try to move the progress bar window..it displays a windows background at the place of displacement and also in the new region or sometimes its getting stuck.Please help me with this!
EDIT2:
message pumping.
while(PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE) && (FALSE == testResult))
    {
       if(msg.message == WM_QUIT)
      {
        DestroyWindow(dialogHandle);
        return TRUE;
       }
      SendMessage(progressBarHandle, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
      SendMessage(progressBarHandle,PBM_SETPOS,0,0);
       ShowWindow(progressBarHandle,SW_SHOW);
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        //return 1;
    }

A:

I'm not sure what behavior you're trying to achieve.
The major problem is that your main window must process the messages in order to behave properly, and you aren't doing it.
while (FALSE == testResult) {
    MSG msg;
    // Here you `reset` the progress bar, one each turn, why?
    SendMessage(progressBarHandle, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
    SendMessage(progressBarHandle,PBM_SETPOS,0,0);
    ShowWindow(progressBarHandle,SW_SHOW);
    Sleep(50); // <-- here you PAUSE main thread for 50 milliseconds

    // myCondition is a bool variable which is decalred globally
    if (TRUE == myCondition) {
          DestroyWindow(dialogHandle);
          AfxMessageBox(L"Test Success");
     }

    // Here you'll loop, and you don't give the main thread a chance to
    // process the message queue.
}

In my opinion, instead of using a Sleep(50); you could setup a timer and use its callback to update the progress bar. That's a naive solution but you can give it a try.
Edit: Perhaps this? I didn't test it.
while (FALSE == testResult) {
    MSG msg;
    // Here you `reset` the progress bar, one each turn, why?
    SendMessage(progressBarHandle, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
    SendMessage(progressBarHandle,PBM_SETPOS,0,0);
    ShowWindow(progressBarHandle,SW_SHOW);
    Sleep(50); // <-- here you PAUSE main thread for 50 milliseconds

    // myCondition is a bool variable which is decalred globally
    if (TRUE == myCondition) {
        AfxMessageBox(L"Test Success")
        DestroyWindow(dialogHandle);
        return TRUE;
    }

    // Process the message queue
    while(PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE)) {
       if(msg.message == WM_QUIT) {
           DestroyWindow(dialogHandle);
           return TRUE;
       }
       TranslateMessage(&msg);
       DispatchMessage(&msg);
    }
}

