1、在String Table中加入一个新ID:ID_INDICATOR_COIN,Caption为“硬币数量”。
2、在MainFrm.cpp中的静态数组indicator中将上面的ID加入:
static UINT indicators[] ={ ID_SEPARATOR, //// status line indicator ID_INDICATOR_COIN,////显示硬币数量指示器 ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,};
3、修改OnDraw函数:
void CDrawCoinView::OnDraw(CDC* pDC){ CDrawCoinDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here for(int i=0;i<pDoc->m_nCoins;i++) { int y=200-10*i; pDC->Ellipse(200,y,300,y-30); pDC->Ellipse(200,y-10,300,y-35); } CString strCoins; //先获得主窗口指针,再获得状态栏指针 CStatusBar *pStatus=(CStatusBar *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR); if(pStatus) { strCoins.Format("硬币:%d",pDoc->m_nCoins); pStatus->SetPaneText(1,strCoins); }}