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

Next we create a brush with standard button face color and used it to fill the grayed image (By default,<br />

the standard button face color is light gray. It can also be customized to other colors):<br />

……<br />

……<br />

brush.CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));<br />

pBrOld=dcColor.SelectObject(&brush);<br />

dcColor.PatBlt<br />

(<br />

0, 0,<br />

bm.bmWidth, bm.bmHeight,<br />

PATCOPY<br />

);<br />

dcColor.SelectObject(pBrOld);<br />

brush.DeleteObject();<br />

dcColor.SetBkColor(RGB(255, 255, 255));<br />

dcColor.SetTextColor(RGB(0, 0, 0));<br />

The button face color is retrieved by calling ::GetSystColor(…) API function. Actually, all the<br />

standard colors defined in the system can be retrieved by calling this function. Next, we draw the<br />

highlighted outline of the grayed bitmap using the standard highlighted color:<br />

……<br />

……<br />

brush.CreateSolidBrush(::GetSysColor(COLOR_BTNHIGHLIGHT));<br />

pBrOld=dcColor.SelectObject(&brush);<br />

pBmpHilightOld=dcMono.SelectObject(&bmpHilight);<br />

dcColor.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth, bm.bmHeight,<br />

&dcMono,<br />

0, 0,<br />

0x00B8074A<br />

);<br />

dcColor.SelectObject(pBrOld);<br />

brush.DeleteObject();<br />

dcMono.SelectObject(pBmpHilightOld);<br />

Also, the shadowed outline is drawn on the grayed image in the same way:<br />

……<br />

brush.CreateSolidBrush(::GetSysColor(COLOR_BTNSHADOW));<br />

pBrOld=dcColor.SelectObject(&brush);<br />

pBmpShadowOld=dcMono.SelectObject(&bmpShadow);<br />

dcColor.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth, bm.bmHeight,<br />

&dcMono,<br />

0, 0,<br />

0x00B8074A<br />

);<br />

dcColor.SelectObject(pBrOld);<br />

brush.DeleteObject();<br />

dcMono.SelectObject(pBmpShadowOld);<br />

dcColor.SelectObject(pBmpOld);<br />

}<br />

return (HBITMAP)bmpGray.Detach();<br />

Finally, some clean up routines. Before this function exits, we call function CBitmap::Detach() to<br />

detach HBITMAP type handle from CBitmap type variable. This is because we want to leave the HBITMAP<br />

handle for further use. If we do not detach it, when CBitmap type variable goes out of scope, the destructor<br />

330

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

Saved successfully!

Ooh no, something went wrong!