class CText : public CElement { public: // Function to display a text element virtual void Draw( CDC* pDC, const CElement* pElement = NULL ) const; // Constructor for a text Element CText( const CPoint& Start, const CPoint& End, const CString& String, const COLORREF& Color ); virtual void Move( const CSize& Size ); protected: CPoint m_StartPoint; // Position of a text element CString m_String; // Text to be displayed CText() {} // Default constructor }; CText::CText( const CPoint& Start, const CPoint& End, const CString& String, const COLORREF& Color ) { m_Pen = 1; m_Color = Color; m_String = String; m_StartPoint = Start; m_EnclosingRect = CRect(Start, End); m_EnclosingRect.NormalizeRect(); } void CText::Draw( CDC*pDC, const CElement* pElement) const { COLORREF Color(m_Color); if ( this == pElement ) { Color = SELECT_COLOR; } // Set the text color and output the text pDC->SetTextColor(Color); pDC->TextOut(m_StartPoint.x, m_StartPoint.y, m_String ); } void CText::Move( const CSize& aSize ) { m_StartPoint += aSize; m_EnclosingRect += aSize; } { CSketcherDoc* pDoc = GetDocument(); if ( pDoc->GetElementType() == TEXT ) { CTextDialog aDlg; if ( aDlg.DoModal() == IDOK ) { // Exit OK so create a text element CSize TextExtent = aDC.GetTextExtent( aDlg.m_TextString ); // Get bottom right of text rectangle - MM_LOENGLISH CPoint BottomRt( point.x + TextExtent.cx, point.y - TextExtent.cy ); CText* pTextElement = new CText( point, BottomRt, aDlg.m_TextString, pDoc->GetElementColor() ); // Add the element to the document pDoc->AddElement(pTextElement); // Get all views updated pDoc->UpdateAllViews( 0, 0, pTextElement ); } return; } m_FirstPoint = point; SetCapture(); }