_C PROGRAMMING COLUMN_ by Al Stevens Listing One class CTextView : public CEditView { CFont newfont; // ... }; Listing Two CTextView::CTextView() { newfont.CreateFont(-13,0,0,0,400,0,0,0,0,1,2,1,49,"Courier"); // ... } Listing Three BOOL CTextView::Create(LPCTSTR lpszClassName,LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { BOOL rtn = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); SetTabStops(16); SetFont(&newfont, TRUE); return rtn; } Listing Four void CTextView::ShowLineColumn() { CEdit& rEdit = GetEditCtrl(); // --- character index of 1st char, current line int nLineIndex = rEdit.LineIndex(-1); // --- current line number int nLineno = rEdit.LineFromChar(nLineIndex); // --- character index of current position int nStartChar, nEndChar; rEdit.GetSel(nStartChar, nEndChar ); // --- read the current line char buf[200]; rEdit.GetLine(nLineno, buf, 200); // --- compute tab character adjustment int col = 0; int tabct = 0; for (int x = 0; x < nEndChar - nLineIndex; x++) { if (x == 200) break; if (buf[x] == '\t') while (++col % 4) tabct++; else col++; } // --- current column number int nColumn = (nEndChar - nLineIndex) + tabct; theApp.ShowLineColumn(nLineno+1, nColumn+1); } Listing Five static UINT indicators[] = { ID_SEPARATOR, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; Listing Six STRINGTABLE DISCARDABLE BEGIN ID_INDICATOR_EXT "EXT" ID_INDICATOR_CAPS "CAP" ID_INDICATOR_NUM "NUM" ID_INDICATOR_SCRL "SCRL" ID_INDICATOR_OVR "OVR" ID_INDICATOR_REC "REC" END Listing Seven static UINT indicators[] = { ID_SEPARATOR, ID_INDICATOR_EXT, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, }; Listing Eight int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { // ... m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_EXT, 0, 120); m_wndStatusBar.SetPaneText(1, ""); } Listing Nine void CMainFrame::ShowStatus(CString& strNewStatus, CString* pstrStatus) { if (pstrStatus != 0) m_wndStatusBar.GetPaneText(1, *pstrStatus); m_wndStatusBar.SetPaneText(1, strNewStatus); m_wndStatusBar.SendMessage(WM_PAINT,0,0); } Listing Ten void CQuincyApp::ShowStatusText(CString& strText, CString* pstrOldText) { CMainFrame* pMainFrame = static_cast(m_pMainWnd); pMainFrame->ShowStatus(strText, pstrOldText); } void CQuincyApp::ShowLineColumn(int nLine, int nColumn) { CString strExt; if (nLine != 0) strExt.Format("Ln %d, Col %d", nLine, nColumn); ShowStatusText(strExt); } Listing Eleven void CTextDocument::Serialize(CArchive& ar) { POSITION pos = GetFirstViewPosition(); ASSERT(pos != NULL); CEditView* pView = static_cast(GetNextView(pos)); ASSERT(pView != NULL); pView->SerializeRaw(ar); if (ar.IsStoring()) ar.Flush(); } Listing Twelve // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; Listing Thirteen // --- suppress initial FileNew command on startup if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew) { // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; } else { // ----- reload documents from the previous session // ... }