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

……<br />

……<br />

class CGDIDoc : public CDocument<br />

{<br />

protected:<br />

}<br />

int m_nBmpFormat;<br />

The following macros are defined in the header file of class CGDIDoc:<br />

#define BMP_FORMAT_NONE 0<br />

#define BMP_FORMAT_MONO 1<br />

#define BMP_FORMAT_16COLOR 2<br />

#define BMP_FORMAT_256COLOR 3<br />

#define BMP_FORMAT_24BIT 4<br />

Variable CGDIDoc::m_nBmpFormat is initialized in the constructor:<br />

……<br />

CGDIDoc::CGDIDoc()<br />

{<br />

}<br />

m_nBmpFormat=BMP_FORMAT_NONE;<br />

Whenever a DIB is loaded, function CGDIDoc::GetColorTableSize(…) will be called by CGDIView::<br />

OnInitialUpdate(), so it is convenient to set CGDIDoc::m_nBmpFormat to an appropriate value to indicate<br />

the image format in this function. The following code fragment shows the modified function<br />

CGDIDoc::GetColorTableSize():<br />

DWORD CGDIDoc::GetColorTableSize(WORD wBitCount)<br />

{<br />

DWORD dwSizeCT;<br />

}<br />

switch(wBitCount)<br />

{<br />

case 1:<br />

{<br />

dwSizeCT=2;<br />

m_nBmpFormat=BMP_FORMAT_MONO;<br />

break;<br />

}<br />

case 4:<br />

{<br />

dwSizeCT=16;<br />

m_nBmpFormat=BMP_FORMAT_16COLOR;<br />

break;<br />

}<br />

case 8:<br />

{<br />

dwSizeCT=256;<br />

m_nBmpFormat=BMP_FORMAT_256COLOR;<br />

break;<br />

}<br />

case 24:<br />

{<br />

dwSizeCT=0;<br />

m_nBmpFormat=BMP_FORMAT_24BIT;<br />

}<br />

}<br />

return dwSizeCT;<br />

305

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

Saved successfully!

Ooh no, something went wrong!