本文整理汇总了C++中BitmapPtr::GetBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ BitmapPtr::GetBitmap方法的具体用法?C++ BitmapPtr::GetBitmap怎么用?C++ BitmapPtr::GetBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitmapPtr
的用法示例。
在下文中一共展示了BitmapPtr::GetBitmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateShareBitmap
BitmapPtr IEToolbar::generateShareBitmap(bool isHot) {
const int textMargin = 3;
const int bitmapHeight = 16;
const int bitmapMargin = 2;
const COLORREF grey = RGB(227, 232, 240);
const COLORREF blue = RGB(57, 86, 149);
// Set colors and plus bitmap
UINT plusIconId = (isHot) ? IDB_SHARE_PLUS : IDB_SHARE_HOT_PLUS;
COLORREF bkColor = (isHot) ? blue : grey;
COLORREF bkFrameColor = (isHot) ? grey : blue;
COLORREF txtColor = (isHot) ? grey : blue;
// Load Plus bitmap and get its properties
BITMAP bm;
BitmapPtr plusIcon = loadBitmap(plusIconId);
plusIcon->GetBitmap(&bm);
int plusIconWidth = bm.bmWidth;
int plusIconHeight = bm.bmHeight;
// Create destination context
CDC memDC;
CFont font;
CDC* deviceContext = CDC::FromHandle(::GetDC(0));
memDC.CreateCompatibleDC(deviceContext);
setFont(&memDC, 14, _T("Sans Serif"), font);
// Get message length in pixels
String message = ResourceMessages::getMessage(kToolbarButtonShare);
SIZE textSize = getMessageLength(message, font);
// Create destination bitmap
BitmapPtr bitmap(new CBitmap());
int bitmapWidth = 2 * textMargin + textSize.cx + 2 * bitmapMargin + plusIconWidth;
bitmap->CreateCompatibleBitmap(deviceContext, bitmapWidth, bitmapHeight);
memDC.SelectObject(getPtr(bitmap));
// Draw background with frame
CRect frame(0, 0, bitmapWidth, bitmapHeight) ;
memDC.FillSolidRect(&frame , bkFrameColor);
CRect rectangle(1, 1, bitmapWidth - 1, bitmapHeight - 1) ;
memDC.FillSolidRect(&rectangle , bkColor);
// Draw message
memDC.SetTextColor(txtColor);
CRect textRect(1 + textMargin, 1, bitmapWidth - 1, bitmapHeight - 1) ;
memDC.DrawText(message.c_str(), message.length(), textRect, DT_SINGLELINE | DT_VCENTER);
// Draw plus bitmap
CDC srcDC;
srcDC.CreateCompatibleDC(NULL);
srcDC.SelectObject(getPtr(plusIcon));
const BOOL bitBltResult = memDC.BitBlt(bitmapWidth - bitmapMargin - plusIconWidth, bitmapMargin,
plusIconWidth, plusIconHeight, &srcDC, 0, 0, SRCCOPY);
if (FALSE == bitBltResult) {
throw Error("Failed to draw share button image/n");
}
// Delete resources
font.DeleteObject();
DeleteDC(srcDC);
DeleteDC(memDC);
return bitmap;
}