11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9. Font<br />

Variables m_nSelIndexBgnOld and m_nSelIndexEndOld are used to remember the old selection indices,<br />

functions GetSelIndexBgnOld() and GetSelIndexEndOld() are used to obtain their values outside class<br />

CGDIDoc. Because we also need to know the value of m_nCaretIndex when updating the client window,<br />

another function GetCaretIndex() is also added for retrieving its value.<br />

Old selection:<br />

Old selection:<br />

New selection:<br />

New selection:<br />

Difference:<br />

Difference:<br />

Selected area<br />

Area needs to be updated<br />

Figure 9-5. Text selection and window update<br />

The value of m_nSelIndexEndOld is initialized in the constructor:<br />

……<br />

CGDIDoc::CGDIDoc()<br />

{<br />

}<br />

m_nSelIndexEndOld=-1;<br />

In the sample, some macros are defined as follows to indicate different updating situations when<br />

function CDocument::UpdateAllViews(…) is called:<br />

#define HINT_DELCHAR_AFTER 100<br />

#define HINT_DELCHAR_BEFORE 101<br />

#define HINT_DELETE_SELECTION 102<br />

#define HINT_PASTE 103<br />

#define HINT_SELECTION 104<br />

#define HINT_UNSELECTION 105<br />

#define HINT_INPUT 106<br />

Calling Function CDocument::UpdateAllViews(…)<br />

We must modify all the function calls to CDocument::UpdateAllViews(…). The following shows the<br />

modifications made to function CGDIDoc::SetCaret(…):<br />

Old Version:<br />

……<br />

void CGDIDoc::SetCaret(CPoint point)<br />

{<br />

}<br />

if(m_nSelIndexBgn == -1)m_nSelIndexBgn=m_nCaretIndex;<br />

else<br />

{<br />

m_nSelIndexEnd=m_nCaretIndex;<br />

UpdateAllViews(NULL);<br />

}<br />

GetCGDIView()->RedrawCaret();<br />

New Version:<br />

274

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!