11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14. Views<br />

CRichEditDoc: CRichEditDoc::m_bRTF. If we want to open “rtf” type files, we need to set this variable<br />

to TRUE. If we want to edit plain ASCII text, we need to set this variable to FALSE.<br />

1) To get or set the format of a paragraph, we can stuff structure PARAFORMAT and call function<br />

CRichEditView::GetParaFormat(…) or CRichEditView::SetParaFormat(…); to get or set the format<br />

of characters, we can stuff structure CHARFORMAT and call function<br />

CRichEditView::SetCharFormat(…) or CRichEditView::SetCharFormat(…).<br />

1) To customize “File Open” dialog box, we need to override function CWinApp::OnFileOpen(…). To<br />

customize “Save As” dialog box, we need to override undocumented function CDocument::DoSave().<br />

1) The following undocumented member functions can be used to implement commands for formatting<br />

characters or paragraph in a rich edit view:<br />

CRichEditView::OnParaCenter();<br />

CRichEditView::OnParaRight();<br />

CRichEditView::OnParaLeft();<br />

CRichEditView::OnCharBold();<br />

CRichEditView::OnCharUnderline();<br />

CRichEditView::OnCharItalic();<br />

6) The styles of tree view and list view can be set by calling function ::SetWindowLong(…). Any style<br />

that can be used in function CTreeCtrl::Create(…) or CListCtrl::Create(…) can be changed<br />

dynamically by using this function.<br />

1) We can call function _chdrive(…) to test if a drive (from drive A to drive Z) exits in the system. If the<br />

function returns -1, the drive does not exit. If it returns 0, the drive is available. We can also call this<br />

function to change the current working drive.<br />

1) Class CFileFind can be used to enumerate all the files and directories under certain directory. To<br />

enumerate files and directories, we can call function CFileFind::FileFind() first then call function<br />

CFileFind::FindNextFile() repeatedly until it returns FALSE.<br />

1) Function CFileFind::IsDirectory() can be used to check if an enumerated object is a directory.<br />

Function CFileFind::IsDot() can be used to check if a directory is “.” or “..”.<br />

1) Function ::SHGetFileInfo(…) can be used to obtain the embedded or shell icons for a file.<br />

1) Notification NM_CLICK can be used to trap mouse clicking events on the tree control. Notification<br />

TVN_ITEMEXPANDING indicates that a node is about to expand.<br />

1) When the user clicks mouse on the tree control, we can call function CTreeCtrl::HitTest(…) to find<br />

out the handle of the item that was clicked.<br />

1) We can call function CListCtrl::SortItems(…) to implement item sorting in the list control. In order<br />

to do this, we must assign each item contained in the list control a parameter, which will be used as the<br />

identification of the item. Then we need to prepare a callback function, within which rules of<br />

comparison are implemented.<br />

1) To search for a specific item by its parameter, we can stuff structure LV_FINDINFO and call function<br />

CListCtrl::FIndItem(…).<br />

1) To respond to the mouse clicking events on the columns of the list control, we need to trap notification<br />

LVN_COLUMNCLICK.<br />

456

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

Saved successfully!

Ooh no, something went wrong!