Advanced MFC Programming

Advanced MFC Programming Advanced MFC Programming

math.hcmuns.edu.vn
from math.hcmuns.edu.vn More from this publisher
11.04.2014 Views

Chapter 9. Font nSelIndexBgn=-1 nSelIndexEnd=-1 nSelIndexBgnOld=-1 nSelIndexEndOld=-1 nSelIndexBgn=2 nSelIndexEnd=3 nSelIndexBgnOld=-1 nSelIndexEndOld=-1 nSelIndexBgn=2 nSelIndexEnd=4 nSelIndexBgnOld=2 nSelIndexEndOld=3 Explanation: 1) Nothing is selected. 2) The third character is selected, since nSelIndexEndOld is -1, the changed area should be calculated from nSelIndexBgn and nSelIndexEnd. 3) The third and fourth characters are selected. Since nSelIndexEndOld is not -1, the changed area should be calculated from nSelIndexEndOld and nSelIndexBgn. Figure 9-6. Update only changed area If we pass FALSE to the second parameter of CWnd::InvalidateRect(…), the client area will be updated without being erased. This can further reduce flickering. Summary: 1) Font can be created from structure LOGFONT. We need to provide the following information when creating a special font: face name, font size (height and width). To add special effects to the text, we need to know if the font is bolded, italic, underlined or strikeout. Also, we can change character’s orientation by setting font’s escapement. 1) All the fonts contained in the system can be enumerated by calling function ::EnumFontFamilies(…). We need to provide a callback function to receive information for each type of font. 1) Function CDC::ExtTextOut(…) can output a text string within a specified rectangle, the area outside the rectangle will not be affected no matter what the text size is. When we call this function, all the area not covered by the text within the rectangle is treated as the background of the text. 1) To implement caret within a window, first we need to create the caret by using one of the following functions: CWnd::CreateSolidCaret(…), CWnd::CreateGrayCaret(…), CWnd::CreateCaret(…). Then we can show or hide the caret by calling either function CWnd::ShowCaret() or CWnd::HideCaret(). 1) Keyboard input events can be trapped by handling WM_KEYDOWN or WM_CHAR message. 1) Mouse cursor can be changed by handling message WM_SETCURSOR. We can load a user designed cursor resource by calling function CWinApp::LoadCursor(…). We can also load a standard cursor by calling function CWinApp::LoadStandardCursor(…). 1) If we call function CDC::SetTextAlign(…) using TA_UPDATECP flag, the window origin will be updated to the end of the text each time funciton CDC::TextOut(…) is called. 1) To use global memory, we need to call ::GlobalAlloc(…) to allocate the buffers, call ::GlobalLock(…) to lock the memory before accessing it, call ::GlobalUnlock(…) to stop accessing the memory, and call ::GlobalFree(…) to release the memory. 1) To access the clipboard, we need to call CWnd::OpenClipboard(…) to open the clipboard, call ::EmptyClipboard() to clear any existing data, call ::SetClipboardData() to put data to the clipboard, and call ::CloseClipboard() to close the clipboard. To get data from the clipboard, after opening it, we need to call function ::GetClipboardData() to obtain a global memory handle, which can be used for accessing the data contained in the clipboard. 1) We can pass hints to function CDocument::UpdateAllViews(…) to indicate different updating situations. The hint can be received in function CView::OnUpdate(…). If we want only a portion of the 280

Chapter 9. Font client window to be updated, we can specify the area with a CRect type variable and use it to call function CWnd::InvalidateRect(…) instead of default function CWnd::Invalidate(…). 281

Chapter 9. Font<br />

client window to be updated, we can specify the area with a CRect type variable and use it to call<br />

function CWnd::InvalidateRect(…) instead of default function CWnd::Invalidate(…).<br />

281

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

Saved successfully!

Ooh no, something went wrong!