Progressbar as Part of Statusbar :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

I would like to implement a progress bar one pane of the statusbar. Current, the statusbar has two panes. Pane 1 (index 0) is the default separator where you see "Ready." The second pane is contains the progressbar. Here is the code.

-----
CRect progressRect;
m_wndStatusBar.GetItemRect(1, &progressRect);
m_ProgressBar.Create(WS_CHILD | WS_VISIBLE | SBPS_NOBORDERS | PBS_SMOOTH, progressRect, this, -1);
m_ProgressBar.SetRange(0, 100);
m_ProgressBar.SetPos(0);
-----

Here is the code that tests the progressbar.

-----
for (int i = 0; i < 100; ++i)
{
{
m_ProgressBar.SetPos(i);
::Sleep(25);
}
}
-----

For some reason, I do not see any sign of the progressbar working. I have an option in the menu to start the for loop. However, I do not see any sign of the progressbar, period. I am using SDI. The code above are all part of main.

Thanks,
Kuphryn
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Can you get the Progress bar working in the view itself?
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
You need to use the CStatusBarCtrl instead, and probably draw it yourself.
That means you need to set one Pane so that it calls one of your functions to update it's view.

CDialogbar may work even better for you, though - look into that.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

Yeah, a member at Codeguru posted a segment of code he used for a something I am trying to implement. He used CDialogBar and CProgressCtrl.

Here is the link to that thread:

http://www.codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vc&Number=367944&page=2&view=collapsed&sb=5

He used some really innovative MFC tools such as the CDialogBar and ShowControlBar() function. I have Jeff Prosise's MFC reference, but I do not remember Prosise mentioning those about those tools.

I had problems getting the code from the link above to run. I got the error "bardlg.cpp" debug error. Maybe you can test it out too.

Thanks,
Kuphryn
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
I receive a responses at CodeProject and Gamedev about the UI thread (main frame) not able to update the progress bar. I am not familiar with the reason behind that.

I would like to have the progress bar in a pane of a statusbar. That means I will have to declare the progress bar in main (UI thread) and update it from there. If the UI thread cannot update the progress bar, then is it possible to even have a progress bar in main (UI thread) at all?

Kuphryn
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
The problem that you face is to get the ProgressBar to paint. The information is getting to the bar, however, the parent window seems to be tripping up the painting of it.

The explanation of the CDialogBar allows you to put in any control and yo have control over the drawing and handling.

With the CStatusBarCtl, you give up the control; that seems to be what is doing you in.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

I manage to get the one I mentioned from LaFlour at Codeguru to work with my program as well.

Kuphryn
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
If the question here is why isn't the bar painting, your test code is the problem. You shouldn't be sleeping for 25ms, you need to go into a loop and pump messages (and break out of the loop after 25ms if that is what you want to do).
Bill
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

I have a question. The author of the progress bar singh posted uses the function PeepAndPump(). He uses it to process other messages while the progress bar updates. I do not see that function in MSDN. Is there a similar function in MFC?

Kuphryn
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
No, you'll need to implement your own, its pretty straightforward tho.
Bill