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

When we copy the image from the memory bitmap to the client window, we must calculate if the<br />

whole bitmap contains valid image. If not, we should draw only the valid part:<br />

……<br />

……<br />

pDC->BitBlt<br />

(<br />

i*size.cx*nRatio,<br />

j*size.cy*nRatio,<br />

(<br />

(i+1)*size.cx*nRatio > bm.bmWidth*nRatio ?<br />

(bm.bmWidth*nRatio-i*size.cx*nRatio):size.cx*nRatio<br />

),<br />

(<br />

(j+1)*size.cy*nRatio > bm.bmHeight*nRatio ?<br />

(bm.bmHeight*nRatio-j*size.cy*nRatio):size.cy*nRatio<br />

),<br />

&m_dcBKMem,<br />

0,<br />

0,<br />

SRCCOPY<br />

);<br />

The grid drawing becomes very easy now. The brush origin can always be set to (0, 0) because both<br />

the horizontal and vertical dimensions of the memory bitmap are even. Before the image contained in the<br />

memory bitmap is copied to the client window, the grid is added if the current ratio is greater than 2 and the<br />

value of CGDIDoc::m_bGridOn is TRUE:<br />

……<br />

……<br />

m_brGrid.UnrealizeObject();<br />

pDC->SetBrushOrg(0, 0);<br />

pBrOld=m_dcBKMem.SelectObject(&m_brGrid);<br />

for(i=0; i

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

Saved successfully!

Ooh no, something went wrong!