With the XStatusBar-class it is very easy to
display text, numbers, bitmaps or progressbars in a statusbar. It
also provides temporary display of text in any pane with
automatic restore of the normal appearance. For example, it is
possible to display a scrolling bitmap in a pane but during a
long operation, a progressbar indicates how long it takes. The
class also provides actions when you click in any pane (also in
dialogbased applications).
In this example, the first pane temporarily changes to a
progressbar. When the long operation ends, it automaticly changes
back to a normal textpane.
What have you to do, to use this class?
The use the XStatusBar-class is quite simple.
First you have change the existing CStatusBar-member
m_wndStatusBar to XStatusBar in your mainframe-headerfile.
XStatusBar m_wndStatusBar;
Second, replace the creation-functions in the
OnCreate()-method of CMainFrame by:
if(!m_wndStatusBar.CreateStatusBar(this, indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; }
Third, define the appearance of the panes. For example
m_wndStatusBar.SetMode(1, XSB_TEXT | DT_CENTER | DT_VCENTER); m_wndStatusBar.SetMode(2, XSB_NUMBER | DT_CENTER); m_wndStatusBar.SetMode(3, XSB_BITMAP| XSB_REPEAT);
For each pane, you can combine the following modes:
XSB_TEST | Display text in this pane |
XSB_NUMBER | Display a number in this pane |
XSB_BITMAP | Display a bitmap in this pane |
XSB_PROGRESS | Display a progressbar in this pane |
XSB_HSCROLL | Scroll the text, number or bitmap in this pane horizontal |
XSB_VSCROLL | Scroll the text, number or bitmap in this pane vertical |
XSB_DSCROLL | Scroll horizontal and vertical |
XSB_REPEAT | Draw the text, number or bitmap multiple times to fill the pane |
XSB_STRETCH | Grow or shrink the bitmap, so that the entire pane was filled |
XSB_SMOOTH | Progressbar was drawn smooth |
XSB_TOP | Align top (like DT_TOP) |
XSB_LEFT | Align left (like DT_LEFT) |
XSB_CENTER | Align center (like DT_CENTER) |
XSB_RIGHT | Align right (like DT_RIGHT) |
XSB_VCENTER | Align vertical center (like DT_VCENTER) |
XSB_BOTTOM | Align bottom (like DT_BOTTOM) |
You can change the mode for every Pane whenever you want.
Fourth, after the mode-definition, you have to tell the panes about further information:
m_wndStatusBar.SetFgColor(1, RGB( 0, 0, 0), RGB(255, 255, 255)); m_wndStatusBar.SetBkColor(1, RGB( 0, 255, 255), RGB(128, 0, 0)); m_wndStatusBar.SetNumber(2, 0, 0); m_wndStatusBar.SetBitmap(3, "BM1", "BM2");
There are a couple of functions to change the appearance of
the panes:
Method | Description | Default |
SetFgColor | Set the pane’s textcolor (Mode XSB_TEXT or XSB_NUMBER) * |
enabled: standard textcolor (e.g. black) disabled: greyed text (e.g. grey) |
SetBkColor | Set the pane’s backgroundcolor (Mode XSB_TEXT or XSB_NUMBER) * |
std-backgroundcolor (e.g. light grey) |
SetBitmap | Set the pane’s bitmap (Mode XSB_BITMAP)* The bitmaps are defined as stringresources. If you use int-resource use MAKEINTRESOURCE(..) |
– |
SetText | Set the pane’s text (Mode XSB_TEXT or XSB_NUMBER) * | Indicatortext (e.g. CAPS, NUM, …) |
SetNumber | Set the pane’s number (Mode XSB_TEXT or XSB_NUMBER) * | – |
SetFont | Set the pane’s font (LOGFONT or CFont, Mode XSB_TEXT or XSB_NUMBER) |
standard textfont (e.g. MS Sans Serif 10pt) |
SetFontSize | Set the pane’s fontsize (Mode XSB_TEXT or XSB_NUMBER) | standard textfontsize (e.g. 10pt) |
SetFontName | Set the pane’s fontname (Mode XSB_TEXT or XSB_NUMBER) | standard textfontname (e.g. MS Sans Serif) |
SetRange | Set the pane’s progressbarrange (see CProgressBar, Mode XSB_PROGRESS) |
0 .. 100 |
SetPos | Set the pane’s progressbarposition (see CProgressBar, Mode XSB_PROGRESS) |
0 |
SetOffset | Set the pane’s progressbaroffset (see CProgressBar, Mode XSB_PROGRESS) |
1 |
SetStep | Set the pane’s progressbarstep (see CProgressBar, Mode XSB_PROGRESS) |
1 |
Increment | Incremet the pane’s numbervalue (Mode XSB_NUMBER) | – |
Decrement | Decremet the pane’s numbervalue (Mode XSB_NUMBER) | – |
* Remeber: You can set two values, one for the enabled pane and one for the disabled pane |
If you only need textpanes, like the standard-statusbar you
don’t need to do step 3 and 4. Now you are ready to use the
class.
What have you to do, to temporarily display a progress bar?
First you have to save the pane’s appearance with SavePane(ix).
Then you can change the mode of the pane to XSB_PROGRESS and set
the progress bars parameters (e.g. SetRange(ix, 0, 100),
SetStep(ix, 2), …). Now it’s time to do your
long operation and step your progressbar (StepIt(ix)).
At last, restore the pane’s appearance (RestorePane(ix)).
m_wndStatusBar.SavePane(0); m_wndStatusBar.SetMode(0, XSB_PROGRESS); m_wndStatusBar.SetRange(0, 0, 100); ... (long operation) ... m_wndStatusBar.RestorePane(0);
What have you to do, to temporarily display a text?
There is another class called XPaneText, to
simplify this action. When you want to show temporar text in a
pane (no matter if the pane is enabled or disabled) just create a
XPaneText-object with the specified text. When you destroy the
object, the original appearance of the pane was restored. For
example, the following code displays the text "Display this
text" in the first pane until you end the dialog. There’s no
matter if the pane was in bitmap-mode or if it was disabled.
{ XPaneText("Display this text"); CTestDialog dlg; dlg.DoModal(); } // Destroy the XPaneText-object ==> Restore pane
How does the application know, which pane was clicked?
First you have to add a normal handler for the mouse-event
(for example ON_WM_LBUTTONDBLCLK()). In the eventhandler, use the
function GetPaneAtPosition(point) to determine,
wich pane belongs to the mouse-position. This function also works
fine in dialogs, because in this case, the point was translatet
into client-corrdinates.
void CMainFrame::OnLButtonDblClk(UINT nFlags, CPoint point) { if (m_wndStatusBar.GetPaneAtPosition(point) == 3) AfxMessageBox("Pane 3 doubleclicked"); else ... }