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 10. Bitmap<br />

COLOR_3DHILIGHT<br />

COLOR_3DHIGHLIGHT<br />

COLOR_BTNHILIGHT<br />

COLOR_BTNHIGHLIGHT<br />

COLOR_3DLIGHT<br />

COLOR_3DSHADOW<br />

COLOR_BTNSHADOW<br />

Highlight color of three-dimensional display elements, this<br />

color is used for drawing edges facing the light source.<br />

Light color of three-dimensional display elements, this color is<br />

used for drawing edges facing the light source.<br />

Shadow color for three-dimensional display elements, this<br />

color is used for drawing edges facing away from the light<br />

source.<br />

In the sample, we choose COLOR_BTNHIGHLIGHT as the highlighted color, and COLOR_BTNSHADOW as the<br />

shadowed color.<br />

New Function<br />

In the sample, a new function CreateGrayedBitmap(…) is declared in class CGDIView to create grayed<br />

image from a nomal bimap:<br />

……<br />

……<br />

……<br />

class CGDIView : public CScrollView<br />

{<br />

public:<br />

}<br />

HBITMAP CreateGrayedBitmap(CBitmap *);<br />

The only parameter to this function is a CBitmap type pointer. The function will return an HBITMAP<br />

handle, which is the grayed bitmap. Within the function, we must prepare three bitmaps: the bitmap that<br />

will be used to store the final grayed image, the mask image that stores the shadowed outline, and the mask<br />

image that stores the highlighted outline. The function starts with creating these bitmaps:<br />

HBITMAP CGDIView::CreateGrayedBitmap(CBitmap *pBmp)<br />

{<br />

BITMAP bm;<br />

CClientDC dc(this);<br />

CDC dcMono;<br />

CDC dcColor;<br />

CBitmap bmpShadow;<br />

CBitmap bmpHilight;<br />

CBitmap bmpGray;<br />

CBitmap *pBmpShadowOld;<br />

CBitmap *pBmpHilightOld;<br />

CBitmap *pBmpOld;<br />

CBrush brush;<br />

CBrush *pBrOld;<br />

……<br />

dcMono.CreateCompatibleDC(&dc);<br />

dcColor.CreateCompatibleDC(&dc);<br />

ASSERT(dcMono.GetSafeHdc());<br />

ASSERT(dcColor.GetSafeHdc());<br />

pBmp->GetBitmap(&bm);<br />

bmpShadow.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);<br />

bmpHilight.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);<br />

bmpGray.CreateCompatibleBitmap(&dc, bm.bmWidth, bm.bmHeight);<br />

pBmpOld=dcColor.SelectObject(pBmp);<br />

The final grayed image will be stored in variable bmpGray. We will refer image created by this variable<br />

as “grayed image”, although the image may not be grayed in the interim.<br />

The other two CBitmap type variables, bmpHilight and bmpShadow will be used to store the outline<br />

mask images. We need two memory DCs, one used to select the color bitmap (normal image passed<br />

through pointer pBmp, and grayed image bmpGray) and one for binary bitmaps (the outline mask bitmaps).<br />

Note that binary bitmaps are created with bit count per pixel set to 1 and the grayed bitmap (actually it is a<br />

328

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

Saved successfully!

Ooh no, something went wrong!