Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 780181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:02:09+00:00 2026-05-14T20:02:09+00:00

I have a simple MFC program which displays the progressbar..I used the below code

  • 0

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;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:02:10+00:00Added an answer on May 14, 2026 at 8:02 pm

    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);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are passing id as a parameter in the link,… May 17, 2026 at 1:41 am
  • Editorial Team
    Editorial Team added an answer If you have a mysql installation somewhere and phpMyAdmin, just… May 17, 2026 at 1:41 am
  • Editorial Team
    Editorial Team added an answer If you use a normal form post only inputs inside… May 17, 2026 at 1:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have to program a simple threaded program with MFC/C++ for a uni assignment.
I have an MFC C++ program that contains two classes, as follows; struct MyStruct
I have a problem with a simple included file. The file being included is
On SQL Server 2005, I have a complex multi-level allocation process which looks like
I wrote my simple desktop program in C#. I am reluctant to distribute it
I have a long-running console-based application Sender that sends simple text to STDOUT using
I have a long-running console-based application Sender that sends simple text to STDOUT using
I have simple 3 tier web application and have mostly CRUDE functionalities. Recently I
I have simple one column HTML files ( ebooks from Gutenberg Project). I want
I have simple HQL query: var list = OpenSession() .CreateQuery(SELECT MAX(p.price) as max_price, COUNT(p.id)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.