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 11. Sample: Simple Paint<br />

1) A region must be selected into DC before being used. The function that can be used to select a region<br />

is CDC::SelectClipRgn(…). To select the region out of the DC, we can simply call this function again<br />

and pass NULL to its parameter.<br />

1) Path can be used to record outputs to the device context. To start path recording, we need to call<br />

function CDC::BeginPath(). To end path recording, we can call function CDC::EndPath(). All the<br />

drawings between the two function calls will be recorded in the path. The output will not appear on the<br />

DC when the recording is undergoing.<br />

1) Function CDC::StrokePath() can be called to stroke the outline of a path. Function CDC::FillPath(…)<br />

can be used to fill the interior of the path. Function CDC::StrokeAndFillPath() can be used to<br />

implement both.<br />

1) Region can be created from an existing path by calling function CRgn::CreateFromPath(…).<br />

1) A region is made up of a series of rectangles. By resizing all the rectangles, we can resize the region.<br />

1) A path is made up of a series of vectors. To resize a path, we can scale all the control points. We can<br />

also change the position of some control points to generate special effects.<br />

1) The standard DIB format that can be used in the clipboard is CF_DIB. To put DIB data to the clipboard,<br />

we need to prepare DIB data with standard DIB format, open the clipboard, empty the clipboard, call<br />

function ::SetClipboardData(…) and pass CF_DIB flag along with the data handle to it. After all these<br />

operations, we must close the clipboard.<br />

1) To obtain DIB data from the clipboard, we can use CF_DIB flag to call function<br />

::GetClipboardData(…).<br />

13) Message WM_PALETTECHANGED is used to notify the applications that the system palette has changed.<br />

Applications that implement logical palettes should realize the logical palette again after receiving this<br />

message to achieve least color distortion.<br />

14) Outputting directly to window may cause flickering sometimes. This is because usually the old<br />

drawings must be erased before the window is updated. To avoid flickering, we can prepare everything<br />

in a memory bitmap, then output the patterns contained in the memory bitmap to the window in one<br />

stroke.<br />

369

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

Saved successfully!

Ooh no, something went wrong!