static void showNormalBitmap(HDC dst, const CPoint &p, HBITMAP bm) {
  HDC srcDC = CreateCompatibleDC(dst);
  const CSize size = getBitmapSize(bm);
  HGDIOBJ oldGdi = SelectObject(srcDC, bm);
  BitBlt(dst, p.x,p.y,size.cx, size.cy, srcDC, 0,0, SRCCOPY);
  SelectObject(srcDC, oldGdi);
  delete srcDC;
}
Beispiel #2
0
HBITMAP loadBitmap(char* path, int* width, int* height) {
    HBITMAP hBitmap;

    hBitmap = (HBITMAP) LoadImage (GetModuleHandle(NULL), path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    if (NULL == hBitmap) {
        printf("Cannot load background image from %s. Using default.\n",path);
        hBitmap = (HBITMAP) LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_PHONE), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
    }
    if (hBitmap == 0) {
        printf("Cannot load background image from resources.\n");
        return NULL;
    }
    getBitmapSize(hBitmap, width, height);
    return hBitmap;
}
Beispiel #3
0
bool IEToolbar::onShareButtonDraw(const NMTBCUSTOMDRAW& messageInfo, 
                                  LRESULT& lResult) {
  const HDC& deviceCntxHadle = messageInfo.nmcd.hdc;
  const UINT itemState = messageInfo.nmcd.uItemState;

  CDC* deviceCntx = CDC::FromHandle(deviceCntxHadle);

  // Prepare device context to load image into.
  CDC memDC;
  memDC.CreateCompatibleDC(deviceCntx);
  memDC.SetMapMode(deviceCntx->GetMapMode());

  // Determine which image load into memory device context and load it.
  const bool isHot = (itemState == CDIS_HOT);
  CBitmap* oldBmp = memDC.SelectObject(isHot ?
      getPtr(shareHotButtonBitmap_) : getPtr(shareButtonBitmap_));

  // Calculate position to draw the image.
  const CRect itemRect = toolbarWindow_.getItemRect(shareButtonIndex_);
  const CSize bitmapSize = getBitmapSize(shareButtonBitmap_);
  const int xOffset = (itemRect.Width() - bitmapSize.cx) / 2;
  const int yOffset = (itemRect.Height() - bitmapSize.cy) / 2;

  // Draw the image.
  const BOOL bitBltResult = deviceCntx->BitBlt(itemRect.left, itemRect.top,
      itemRect.Width(), itemRect.Height(), &memDC, -xOffset, -yOffset, SRCCOPY);
  if (FALSE == bitBltResult) {
    throw Error("Failed to draw share button image/n");
  }

  memDC.SelectObject(oldBmp);

  lResult = CDRF_SKIPDEFAULT;

  return true;
}