BOOL CPictureObj::Create(IStream *pStream, long x, long y, long cx, long cy) { ASSERT(pStream != NULL); ASSERT(m_pPicture == NULL); BOOL bResult = FALSE; LPPICTURE pic = NULL; HRESULT hr = ::OleLoadPicture(pStream, 0, TRUE, IID_IPicture, (void**)&pic); if(SUCCEEDED(hr) && pic != NULL) { m_pPicture = new CResizableImage; m_pPicture->Create(pic); this->x = x; this->y = y; if(cx > 0 && cy > 0) { this->cx = cx; this->cy = cy; } else { pic->get_Width(&m_RealSize.cx); pic->get_Height(&m_RealSize.cy); HiMetricToPixel(&m_RealSize, &m_RealSize); this->cx = m_RealSize.cx; this->cy = m_RealSize.cy; } pic->Release(); bResult = TRUE; } return bResult; }
void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds) { if( isVisible() ) { long width = lprcBounds->right-lprcBounds->left; long height = lprcBounds->bottom-lprcBounds->top; RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom }; if( isUserMode() ) { /* VLC is in user mode, just draw background color */ COLORREF colorref = RGB(0, 0, 0); OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref); if( colorref != RGB(0, 0, 0) ) { /* custom background */ HBRUSH colorbrush = CreateSolidBrush(colorref); FillRect(hdcDraw, &bounds, colorbrush); DeleteObject((HANDLE)colorbrush); } else { /* black background */ FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH)); } } else { /* VLC is in design mode, draw the VLC logo */ FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH)); LPPICTURE pict = getPicture(); if( NULL != pict ) { OLE_XSIZE_HIMETRIC picWidth; OLE_YSIZE_HIMETRIC picHeight; pict->get_Width(&picWidth); pict->get_Height(&picHeight); SIZEL picSize = { picWidth, picHeight }; if( NULL != hicTargetDev ) { DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1); } else if( NULL != (hicTargetDev = CreateDevDC(ptd)) ) { DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1); DeleteDC(hicTargetDev); } if( picSize.cx > width-4 ) picSize.cx = width-4; if( picSize.cy > height-4 ) picSize.cy = height-4; LONG dstX = lprcBounds->left+(width-picSize.cx)/2; LONG dstY = lprcBounds->top+(height-picSize.cy)/2; if( NULL != lprcWBounds ) { RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom }; pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy, 0L, picHeight, picWidth, -picHeight, &wBounds); } else pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy, 0L, picHeight, picWidth, -picHeight, NULL); pict->Release(); } SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH)); MoveToEx(hdcDraw, bounds.left, bounds.top, NULL); LineTo(hdcDraw, bounds.left+width-1, bounds.top); LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1); LineTo(hdcDraw, bounds.left, bounds.top+height-1); LineTo(hdcDraw, bounds.left, bounds.top); } } };