MFC visual c++ CstringArray Example

In this MFC visual c++ CstringArray example we used CstringArray class in order to display time on status bar bans we used it to display seconds , minutes and hours

1 - Build MFC application single document and chose not to select printing and printing preview
2 - Add resource element in the View menu chose resource simbols and New and name it ID_TIMEARRAY
3-Add handlers in the CmainFrame for ID_VIEW_STATUS_BAR and update handler for it,
4-Replace the previously created indicators array with 3 ID_SEPARATOR to hold second minutes and hours respectively and make m_wndStatusBar data member public instead of private .
5- Replace if (!m_wndStatusBar.Create(this) with this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, ID_TIMEARRAY) ;so as not to use the default status bar .
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);
} in mainframe.cpp

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 ");
and add
#include "MainFrm.h" near the top of your view class
8- ADd the following code to OnLbuttonDown handler in your view class
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;

CStringArray timearray ;
CString strsec ,strmin ,strhours ;
strsec.Format("%d ",sec);
strmin.Format("%d " , min);
strhours.Format("%d " ,hours );
timearray[0] = strsec ;
timearray[1] = strmin ;
timearray[2] = strhours ;

pStatus->SetPaneText(0, timearray[0]);
pStatus->SetPaneText(1 ,timearray[1] );
pStatus->SetPaneText(2 ,timearray[2]);

to download the whole project clock here

to download the Exe file click here


  1. please give example of array with CString only...


leave me messege