Progress Bar Control

Hi,

I have a dialog in my resources, which has on it a progress bar control.

This dialog has attached cpp and header files, so that i have a PROGRESS_BAR_DLG class now. All I do is,

PROGRESS_BAR_DLG dlg;

dlg.DoModal();

This displays the dialog fine but obviously nothing happens

I tried in the InitDialog method putting a CProgressCtrl and then this line of code

progress.Create(PBS_SMOOTH,rect,this,IDC_PROGRESS_BAR);

Which worked fin but any refernce to that control

dlg.progress.the method i want to use. throws an error. I suspect i havent set it up correclty etc. How do i do this...in a very rudimentary way.

Also I have noticed that no other code gets executed until i close that dialog down in some way. This is due to the modal state i assume...How do i allow the dialog to be shown, whilst other work is being done in the background. The progress of this work is obviously going to determine how far the progress bar has gone....i suspect this means i have to put the dialog on a different thread if so, how do i do this,

Thanks in advance

Will



Answer this question

Progress Bar Control

  • Thorben

    If you have already a progress bar in your resource there is no need to create a second one with Create!

    Define a CProgressCtrl member in your dialog and than assign this ID in the resource to the member variable.

    After this is done you can use StepIt!

    for (int i=0; i<100; ++i)
    {
    m_pgBar.StepIt();
    ::Sleep(200);
    }
    This will advance the bar in 100 (default) steps every 200msec.

    But note! Also you have no reentrancy. Read the article it describes the problems with the message loop.



  • Dirk4088

     wdhough wrote:
    I have a dialog in my resources, which has on it a progress bar control.

    This dialog has attached cpp and header files, so that i have a PROGRESS_BAR_DLG class now.  All I do is,

    PROGRESS_BAR_DLG dlg;

    dlg.DoModal();

    And what do you expect to happen, except that there is an empty progressbar that does nothing

    Also creating a new progress bar does nothing than again creating an empty one.

    There is no automagic behind a progress bar.
    What is your problem

    When you have a Modal dialog always no other code is executed! Thats the usual behaviour of a modal dialog.

    Read this article, because I think it covers what you want.
    http://www.microsoft.com/msj/0798/c0798.aspx

     

     



  • mcjack

    that link seems to deal with threads mostly, which is slightly ahead of the current problem but thanks for reccommeding it....it does indeed look helpful.

    my problem is that the line i mentioned before

    progress.Create(PBS_SMOOTH,rect,this,IDC_PROGRESS_BAR);

    causes a run-time error.

    Also as you mentioned i seem to have to progress bar controls.

    the one in resources is called "ID_PROGRESS_BAR". how would i manipulate this bar. ie set its range, set its position, step it up etc....thats what i need to know.

    At the moment i'm just trying to get the bar to run through from start to end, i'm trying to get an understanding of them, but i cant even get em to work!

    thanks

    will


  • AnonUno

    Read my post again. I was to fast clicking send...

  • paolog

    Ether use the ShowWindow method of the dialog, or just set the visible stylein the dialog resource. (WS_VISIBLE)

  • Alek Davis

    hmm,

    ok i have read that article.....and it makes sense but like i said seems to be a little ahead of me, i would just like to display a dialog that will move through a progress bar, in the way you mentioned.

    In your last post you said

    "Define a CProgressCtrl member in your dialog and than assign this ID in the resource to the member variable."

    How are we "defining" this. I hope i'm not being stupid about that.

    In my header file i have CProgressCtrl progress;

    and then in my InitDialog i have

    progress.Create(PBS_SMOOTH,rect,this,IDC_PROGRESS_BAR);

    This is the only way i can think of to "assign the resource" which is IDC_PROGRESS_BAR.

    and then in another part of my code (the part that is calling the dialog) i have this

    PROGRESS_DLG dlg;

    for (int i=0; i<100; ++i)

    {

    dialog.progress.StepIt();

    ::Sleep(200);

    }

    and it fails. So what am i doing wrong

    sorry if i'm being dense here

    Will


  • TheRata

    Ok my mistake, i read a bit more about modeless dialogs and it mentioned about calling the create function in the constructor of my derived dialog. So thats all going well. so when It ran I clicked the button, etc and the program kinda froze for a while (i assume this was whilst it was going through the loop, since i didnt provided andy abort check option) and then after a while the program became responsive again, so that appears to be working. However the dialog was never diaplayed. I couldnt see it at all. Is there some sort of "show" command i'm missing

    Thanks for your help on this

    Will


  • edward zhou

    whats your point


  • Progress Bar Control