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

SRCCOPY<br />

);<br />

m_dcMemBS.BitBlt<br />

(<br />

0,<br />

0,<br />

bm.bmWidth,<br />

bm.bmHeight,<br />

&m_dcMem,<br />

0,<br />

0,<br />

SRCINVERT<br />

);<br />

m_dcMemBS.BitBlt<br />

(<br />

0,<br />

0,<br />

bm.bmWidth,<br />

bm.bmHeight,<br />

&m_dcMemMask,<br />

0,<br />

0,<br />

SRCAND<br />

);<br />

m_dcMemBS.BitBlt<br />

(<br />

0,<br />

0,<br />

bm.bmWidth,<br />

bm.bmHeight,<br />

&m_dcMem,<br />

0,<br />

0,<br />

SRCINVERT<br />

);<br />

pDC->BitBlt<br />

(<br />

0,<br />

0,<br />

bm.bmWidth,<br />

bm.bmHeight,<br />

&m_dcMemBS,<br />

0,<br />

0,<br />

SRCCOPY<br />

);<br />

}<br />

pDC->SelectPalette(pPalOld, FALSE);<br />

In the above function, the pattern on the target device is first copied to the memory bitmap. Then<br />

function CDC::BitBlt(…) is called three times to draw the normal image and mask image on the memory<br />

bitmap, with two XOR drawings of the normal image (first and thrid operations) and one AND mode<br />

drawing of the mask image (second operation). Finally, the new pattern in the memory bitmap is copied<br />

back to the targert device.<br />

Adding Background<br />

If the window’s background is also white, it is difficult for us to see the transparency effect. To show<br />

this effect, in the sample, the background of the client window is also painted with a bitmap image.<br />

The image that is used to paint the background is prepared as a resource, whose ID is IDB_BITMAPBKD.<br />

The bitmap is loaded to variable CGDIView::m_bmpBkd in function CGDIView:: OnInitialUpdate():<br />

void CGDIView::OnInitialUpdate()<br />

{<br />

CGDIDoc *pDoc;<br />

HGLOBAL hData;<br />

322

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

Saved successfully!

Ooh no, something went wrong!