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 14. Views<br />

szFind=newName;<br />

szFind.MakeLower();<br />

iBad=szFind.Find(".txt");<br />

if(iBad != -1)newName.ReleaseBuffer(iBad);<br />

newName+=".rtf";<br />

}<br />

else<br />

{<br />

szFind=newName;<br />

szFind.MakeLower();<br />

iBad=szFind.Find(".rtf");<br />

if(iBad != -1)newName.ReleaseBuffer(iBad);<br />

newName+=".txt";<br />

}<br />

……<br />

}<br />

else<br />

{<br />

if(dlg.m_ofn.nFilterIndex == 1)<br />

{<br />

newName+=".rtf";<br />

}<br />

else newName+=".txt";<br />

}<br />

We can compare CWordPadDoc::DoSave(…) with the default <strong>MFC</strong> function CDocument::DoSave(…).<br />

Formatting Text<br />

Another feature we want to let this editor have is text formatting. For example, we may let the user<br />

format the selected text using bolded, italic or underlined style. Or we may let the user change the<br />

alignment of the selected paragraph (make the whole paragraph aligned left, centered or aligned right). The<br />

two types of formatting are called Character Formatting and Paragraph Formatting respectively, they can<br />

be implemented through calling functions CRichEditView::SetParaFormat(…) and CRichEditView::<br />

SetCharFormat(…). The following shows the formats of the two functions:<br />

void CRichEditView::SetParaFormat(PARAFORMAT &pf);<br />

void CRichEditView::SetCharFormat(CHARFORMAT cf);<br />

Because there are many properties we can set, we need to use structures PARAFORMAT and CHARFORMAT<br />

to specify which properties will be customized. The following is the format of structure PARAFORMAT:<br />

typedef struct _paraformat {<br />

UINT cbSize;<br />

_WPAD _wPad1;<br />

DWORD dwMask;<br />

WORD wNumbering;<br />

WORD wReserved;<br />

LONG dxStartIndent;<br />

LONG dxRightIndent;<br />

LONG dxOffset;<br />

WORD wAlignment;<br />

SHORT cTabCount;<br />

LONG rgxTabs[MAX_TAB_STOPS];<br />

} PARAFORMAT;<br />

We need to set the corresponding bits of member dwMask in order use other members of this structure.<br />

For example, if we want to set paragraph alignment, we need to assign member wAllignment an<br />

appropriate value, and set PFM_ALIGNMENT bit of member dwMask. If this bit is not set, member wAlignment<br />

will have no effect when function CRichEditView::SetParaFormat(…) is called.<br />

There are a lot of features we can set through using this function, which include text numbering (using<br />

bullets at the beginning of each line), paragraph start indent, right indent, second line offset, paragraph<br />

alignment and tabs.<br />

433

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

Saved successfully!

Ooh no, something went wrong!