Advanced MFC Programming
Advanced MFC Programming Advanced MFC Programming
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
- Page 245 and 246: Chapter 8. DC, Pen, Brush and Palet
- Page 247 and 248: Chapter 8. DC, Pen, Brush and Palet
- Page 249 and 250: Chapter 8. DC, Pen, Brush and Palet
- Page 251 and 252: Chapter 8. DC, Pen, Brush and Palet
- Page 253 and 254: Chapter 9. Font Here, member lfFace
- Page 255 and 256: Chapter 9. Font } dlg.m_bBgdStyle=m
- Page 257 and 258: Chapter 9. Font The first element o
- Page 259 and 260: Chapter 9. Font int CALLBACK EnumFo
- Page 261 and 262: Chapter 9. Font for(i=0; iGetSafeHa
- Page 263 and 264: Chapter 9. Font }; Variable m_nRang
- Page 265 and 266: Chapter 9. Font Frame border is gra
- Page 267 and 268: Chapter 9. Font CFont *ptrFont; if(
- Page 269 and 270: Chapter 9. Font POINT pt; CClientDC
- Page 271 and 272: Chapter 9. Font } if(dlg.DoModal()
- Page 273 and 274: Chapter 9. Font In this function, W
- Page 275 and 276: Chapter 9. Font } CScrollView::OnKe
- Page 277 and 278: Chapter 9. Font …… } nKeyState=
- Page 279 and 280: Chapter 9. Font To check out if the
- Page 281 and 282: Chapter 9. Font the same, it indica
- Page 283 and 284: Chapter 9. Font } if(m_nSelIndexBgn
- Page 285 and 286: Chapter 9. Font GHND GPTR Same with
- Page 287 and 288: Chapter 9. Font …… } { Since th
- Page 289 and 290: Chapter 9. Font Function CDocument:
- Page 291 and 292: Chapter 9. Font …… void CGDIDoc
- Page 293 and 294: Chapter 9. Font …… { } UpdateAl
- Page 295: Chapter 9. Font …… …… case
- Page 299 and 300: Chapter 10. Bitmap ); DWORD dwRop T
- Page 301 and 302: Chapter 10. Bitmap Sample 10.1-2\GD
- Page 303 and 304: Chapter 10. Bitmap The next part of
- Page 305 and 306: Chapter 10. Bitmap Sample Sample 10
- Page 307 and 308: Chapter 10. Bitmap } pPalDraw=pDoc-
- Page 309 and 310: Chapter 10. Bitmap Member bfType mu
- Page 311 and 312: Chapter 10. Bitmap …… dwSize=bf
- Page 313 and 314: Chapter 10. Bitmap …… …… }
- Page 315 and 316: Chapter 10. Bitmap Now the size of
- Page 317 and 318: Chapter 10. Bitmap fuColorUse Speci
- Page 319 and 320: Chapter 10. Bitmap if(hData != NULL
- Page 321 and 322: Chapter 10. Bitmap …… …… cl
- Page 323 and 324: Chapter 10. Bitmap used as the orig
- Page 325 and 326: Chapter 10. Bitmap With the above i
- Page 327 and 328: Chapter 10. Bitmap …… …… if
- Page 329 and 330: Chapter 10. Bitmap …… } } { if(
- Page 331 and 332: Chapter 10. Bitmap …… } rgbQuad
- Page 333 and 334: Chapter 10. Bitmap DIB Section Both
- Page 335 and 336: Chapter 10. Bitmap } } if(m_pBmpMas
- Page 337 and 338: Chapter 10. Bitmap …… m_pBmpOld
- Page 339 and 340: Chapter 10. Bitmap BITMAP bm; …
- Page 341 and 342: Chapter 10. Bitmap Draw this portio
- Page 343 and 344: Chapter 10. Bitmap 1) Paint the des
- Page 345 and 346: Chapter 10. Bitmap color bitmap, bu
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