visual c++ Status bar example

1- Make single document MFC application and deselect printing and printview options
2- In the view menu chose resource and then add New resource and then add ID_TIME_STATUSBAR and accept the defaul value (101) .
3- Add message handler and update message handler in the CMainFrame class for both ID_VIEW_STATUS_BAR .
4- Re
place the previously created indicators array with single ID_SEPARATOR and make sure that the CMainFrame data member m_wndStatusBar is public instead of protected so that it can be accessed from the View class .
5- Replace if (!m_wndStatusBar.Create(this) with this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, ID_TIME_STATUSBAR) ;

6- Add the following code to ur CMainFrame.cpp
void CMainFrame::OnViewStatusBar()
m_wndStatusBar.ShowWindow((m_wndStatusBar.GetStyle() &
WS_VISIBLE) == 0);

void CMainFrame::OnUpdateViewStatusBar(CCmdUI* pCmdUI)
pCmdUI->SetCheck((m_wndStatusBar.GetStyle() & WS_VISIBLE) != 0);
7- Add the following function OnDraw to your View class pDC->TextOut(30, 30 ,Press the left key to see your computer current time on the status bar ");

Edit OnDraw messege handler as follows

CTime currenttime = GetCurrentTime();
int sec , min , hours ;
hours = currenttime.GetHour();
min = currenttime.GetMinute();
sec = currenttime.GetSecond();
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
CStatusBar* pStatus = &pFrame->m_wndStatusBar;
CString strtime ;
strtime.Format( "%d %d %d ", hours,min , sec );
pStatus->SetPaneText(0, strtime );

Finally include #include "MainFrm.h" near the top with other include statements

to download the exe file click here

and the whole project here
this contains sum errors


  1. thanks very helpful


leave me messege