27.4 Writing to the status bar
The CFrameWnd::SetMessageText
method lets you write a string into the status bar. MFC provides us with a CString
class that makes it very easy to create strings. In order to write the values of program parameters into a string, we use a CString::Format
method, which behaves very much like the C language printf
function. The operator=
and operator+
are overloaded for CString, with the operator+
doing the logical thing of concatenating one string onto the end of another.
We write a little helper method called updateStatusBar
for our CPopView
class. As we mentioned before, we'll have our CPopView::OnSetCursor
call updateStatusBar, so that the status bar will reflect information about whichever window is currently under the cursor. In addition, we will need to call updateStatusBar
at the bottom of our OnLButtonDown
code because if you click the mouse without actually moving it, then your CView
won't get an OnSetCursor
call.
void CPopView::updateStatusBar()
{
CMainFrame* cMainFrame = (CMainFrame*)::AfxGetMainWnd();
cMainFrame->SetMessageText(pgame()->statusMessage());
//Write to status bar
}
What goes into the actual statusMessage string is up to the individual game. You can look back to our section on the cGame
class for the default game.cpp code for this method.
|