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 />

……<br />

}<br />

DECLARE_DYNCREATE(CGDIView)<br />

Altogether there are four CBitmap type variables, three CBitmap type pointers, three CDC type variables,<br />

and three CPalette type pointers. Their meanings are explained in the following table:<br />

Variable<br />

m_bmpDraw<br />

m_bmpMask<br />

m_bmpBS<br />

m_dcMem<br />

m_dcMemMask<br />

m_dcMemBS<br />

m_pBmpOld<br />

m_pBmpMaskOld<br />

m_pBmpBSOld<br />

m_pPalOld<br />

m_pPalMaskOld<br />

m_pPalBSOld<br />

Meaning<br />

Load the normal bitmap image.<br />

Store the mask bitmap image.<br />

Used for creating memory bitmap.<br />

Selects m_bmpDraw.<br />

Selects m_bmpMask.<br />

Selects m_bmpBS.<br />

Used for selecting m_bmpDraw out of m_dcMem.<br />

Used for selecting m_bmpMask out of m_dcMemMask.<br />

Used for selecting m_bmpBS out of m_dcMemBS.<br />

Used for selecting the logical palette out of m_dcMem.<br />

Used for selecting the logical palette out of m_dcMemMask.<br />

Used for selecting the logical palette out of m_dcMemBS.<br />

To make the application more interesting, we will also draw the background of client window using<br />

bitmap. This bitmap will be loaded into m_bmpBkd variable.<br />

The six pointers are initialized to NULL in the constructor:<br />

CGDIView::CGDIView()<br />

{<br />

m_bBitmapLoaded=FALSE;<br />

m_pBmpOld=NULL;<br />

m_pBmpMaskOld=NULL;<br />

m_pBmpBSOld=NULL;<br />

m_pPalOld=NULL;<br />

m_pPalMaskOld=NULL;<br />

m_pPalBSOld=NULL;<br />

}<br />

Cleaning Up<br />

A new function CGDIView::CleanUp() is added to the application for doing the clean up job. Within<br />

this function, all the objects selected by the DCs are selected out, then DCs and bitmaps are deleted:<br />

void CGDIView::CleanUp()<br />

{<br />

if(m_pPalOld != NULL)<br />

{<br />

m_dcMem.SelectPalette(m_pPalOld, FALSE);<br />

m_pPalOld=NULL;<br />

}<br />

if(m_pPalMaskOld != NULL)<br />

{<br />

m_dcMemMask.SelectPalette(m_pPalMaskOld, FALSE);<br />

m_pPalMaskOld=NULL;<br />

}<br />

if(m_pPalBSOld != NULL)<br />

{<br />

m_dcMemBS.SelectPalette(m_pPalBSOld, FALSE);<br />

m_pPalBSOld=NULL;<br />

}<br />

if(m_pBmpOld != NULL)<br />

{<br />

m_dcMem.SelectObject(m_pBmpOld);<br />

m_pBmpOld=NULL;<br />

318

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

Saved successfully!

Ooh no, something went wrong!