Warning: usage policy was updated. Please read carefully!
This set of classes provide an expandable framework for the syntax coloring text editor.
The package consists of three main classes:
class CSampleDoc : public CDocument { // code omitted // Attributes public: class CSampleTextBuffer : public CCrystalTextBuffer { private: CSampleDoc *m_pOwnerDoc; public: CSampleTextBuffer(CSampleDoc *pDoc) { m_pOwnerDoc = pDoc; }; virtual void SetModified(BOOL bModified = TRUE) { m_pOwnerDoc->SetModifiedFlag(bModified); }; }; CSampleTextBuffer m_xTextBuffer; };
class CSampleView : public CCrystalEditView { // code omitted protected: virtual CCrystalTextBuffer *LocateTextBuffer(); }
CCrystalTextBuffer *CSampleView::LocateTextBuffer() { CSampleDoc *pDoc = (CSampleDoc *) GetDocument(); return &pDoc->m_xTextBuffer; }
virtual DWORD ParseLine(DWORD dwCookie, int nLineIndex, TEXTBLOCK *pBuf, int &nActualItems); struct TEXTBLOCK { int m_nCharPos; // Offset from beginning of the line int m_nColorIndex; // Type of the block being defined: COLORINDEX_NORMALTEXT, // COLORINDEX_KEYWORD, COLORINDEX_COMMENT, etc. };
// This is the continuous double-slash comment.\ you see, it is really continuous ! #define MESSAGE "And this is continuous preprocessor directive.\n"\ "And this is its second line."
protected: virtual int GetLineCount(); virtual int GetLineLength(int nLineIndex); virtual LPCTSTR GetLineChars(int nLineIndex);
int CSampleView::GetLineCount() { // Please note that we must always return at least 1 line. // Even empty text has a single *empty* line! CSampleDoc *pDoc = (CSampleDoc *) GetDocument(); return pDoc->m_strarrLines.GetSize(); } int CSampleView::GetLineLength(int nLineIndex) { CSampleDoc *pDoc = (CSampleDoc *) GetDocument(); return pDoc->m_strarrLines[nLineIndex].GetLength(); } LPCTSTR CSampleView::GetLineChars(int nLineIndex) { CSampleDoc *pDoc = (CSampleDoc *) GetDocument(); return pDoc->m_strarrLines[nLineIndex]; }
Download demo project - 117 KB.
Download source - 45 KB.
Date Posted: January 15, 1999 Last updated: March 23, 1999
Add Comment
INSTANT EXPERTS!Savvy IT Pros report on SupportSource. Take a look inside the largest vault of multi-vendor computing specs ever assembled. Click here for an In-depth Report,. Learn about Free & Open Source software at the Bazaar Conference & Expo!,December 14-16, 1999 in New York City! Click here for more information. For tons of Windows technology resources, check out the Windows Programming directory. Go to Fatbrain for the NEWEST and BEST technical books for IT professionals. Get Linux Utilities for ONLY $34.95 at EarthWeb Direct.