New Features for the Statusbar in MFC - Progress bar
(Page 3 of 4 )
It is always a good idea to remind the user of the status of the data procession, if possible. Adding a little progress bar inside the Statusbar is one of the best solutions.
A progress bar requires its own pane. Create one with the ID of ID_PROG_BAR. Add any default text, as the size it does not matter. We will change it.
int id = m_wndStatusBar.CommandToIndex(ID_PROG_BAR;
m_wndStatusBar.SetPaneWidth(id, 100);
m_wndStatusBar.EnablePaneProgressBar (id, 100);
The short code snippet above is all you need to get it up and working. To simulate it I decided to increase the progress by one at every OnTimer call (so every single second). I set 100 pixels as the length of the progress bar and set the maximum value of the progress bar to one hundred with the second function (besides enabling it). You can use the following method to ensure a nice demo (add it at the end of OnTimer function):
if(m_alfa == 100)
m_alfa = 0;
m_wndStatusBar.SetPaneProgress( m_wndStatusBar.CommandToIndex(ID_PROG_BAR), ++m_alfa);
Most of the time you may want to modify this from other classes. If this is the case, you need to create a method for accessing the Statusbar. The most advisable is to implement a member function of the mainframe that returns a reference or pointer. You can ask for the mainframe's pointer from any class via the following line:
((CMainFrame*) AfxGetMainWnd ())->GetStatusBar().SetPaneText(…);
if the GetStatusbar is defined as:
CMFCStatusBar& CMainFrame::GetStatusBar()
{
return m_wndStatusBar;
}
Next: Double click response >>
More .NET Articles
More By Gabor Bernat