Exemple #1
0
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;
}
Exemple #2
0
/*static */
bool display_t::save_bitmap(const char *szFileName, HBITMAP bmp, HPALETTE pal /*= NULL*/)
{
	START_FUNCTION_BOOL();

	PICTDESC pdPictDesc;
	pdPictDesc.cbSizeofstruct = sizeof(PICTDESC);
	pdPictDesc.picType = PICTYPE_BITMAP;
	pdPictDesc.bmp.hbitmap = bmp;
	pdPictDesc.bmp.hpal = pal;

	LPPICTURE plPicture = NULL;
	HRESULT hResult = OleCreatePictureIndirect(&pdPictDesc, IID_IPicture, false, reinterpret_cast<void**>(&plPicture));

	if (!SUCCEEDED(hResult))
	{
		break;
	}

	LPSTREAM lpStream = NULL;
	hResult = CreateStreamOnHGlobal(0, true, &lpStream);

	if (!SUCCEEDED(hResult))
	{
		plPicture->Release();
		return false;
	}

	LONG lBytesStreamed = 0;
	hResult = plPicture->SaveAsFile(lpStream, true, &lBytesStreamed);

	HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

	if (!SUCCEEDED(hResult) || !hFile)
	{
		lpStream->Release();
		plPicture->Release();
		break;
	}

	HGLOBAL hgMemory = 0;
	GetHGlobalFromStream(lpStream, &hgMemory);
	LPVOID lpData = GlobalLock(hgMemory);

	DWORD dwBytesWritten = 0;

	bool bResult = !!WriteFile(hFile, lpData, lBytesStreamed, &dwBytesWritten, 0);
	bResult &= (dwBytesWritten == static_cast<DWORD>(lBytesStreamed));

	GlobalUnlock(hgMemory);
	CloseHandle(hFile);

	lpStream->Release();
	plPicture->Release();

	END_FUNCTION_BOOL();
}
/////////////////////////////////////////////////////////////////////////////////////////
// Utility to save a bitmap to file for later examination. Used for debugging only.
// Based on an article by "gelbert" on www.experts-exchange.com at
// http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20193761.html
//
// This version is a member function and instead of taking an HBITMAP as the 2nd
// parameter, it take a reference to a CBitmap. Otherwise, it is identical.
/////////////////////////////////////////////////////////////////////////////////////////
BOOL CSliderCtrlEx::SaveBitmap(LPCSTR lpFileName, CBitmap &hBitmap, HPALETTE hPal)
{
	BOOL bResult = FALSE;
	
	PICTDESC stPictDesc;
	stPictDesc.cbSizeofstruct = sizeof(PICTDESC);
	stPictDesc.picType = PICTYPE_BITMAP;
	stPictDesc.bmp.hbitmap = hBitmap;
	stPictDesc.bmp.hpal = hPal;
	
	LPPICTURE pPicture;
	HRESULT hr = OleCreatePictureIndirect( &stPictDesc, IID_IPicture, FALSE,
		reinterpret_cast<void**>(&pPicture) );
	if ( SUCCEEDED(hr) )
	{
		LPSTREAM pStream;
		hr = CreateStreamOnHGlobal( NULL, TRUE, &pStream );
		if ( SUCCEEDED(hr) )
		{
			long lBytesStreamed = 0;
			hr = pPicture->SaveAsFile( pStream, TRUE, &lBytesStreamed );
			if ( SUCCEEDED(hr) )
			{
				HANDLE hFile = CreateFile(_T(lpFileName), 
					GENERIC_WRITE, 
					FILE_SHARE_READ, 
					NULL,
					CREATE_ALWAYS, 
					FILE_ATTRIBUTE_NORMAL, 
					NULL );
				if ( hFile )
				{
					HGLOBAL hMem = NULL;
					GetHGlobalFromStream( pStream, &hMem );
					LPVOID lpData = GlobalLock( hMem );
					
					DWORD dwBytesWritten;
					bResult = WriteFile( hFile, lpData, lBytesStreamed, &dwBytesWritten, NULL );
					bResult &= ( dwBytesWritten == (DWORD)lBytesStreamed );
					
					// clean up
					GlobalUnlock(hMem);
					CloseHandle(hFile);
				}
			}
			// clean up         
			pStream->Release();
		}
		// clean up      
		pPicture->Release();
	}
	
	return bResult;   
}
Exemple #4
0
HRESULT CResizableImage::Create(LPPICTURE &pImage, const LPSIZE pRealSize)
{
	_ASSERTE(m_pImage==NULL);

	HRESULT hr	=	S_OK;
	
	if(pImage!=NULL)
		hr = pImage->QueryInterface(IID_IPicture,(void**)&m_pImage);

	if(SUCCEEDED(hr))
	{
		m_pImage->get_Width(&m_ImageSize.cx);
		m_pImage->get_Height(&m_ImageSize.cy);
		if(pRealSize)
		{
			memcpy(&m_RealSize,pRealSize,sizeof(SIZE));
			//PixelToHiMetric(&m_RealSize,&m_RealSize);
		}
		else 
		{
			m_pImage->get_Width(&m_RealSize.cx);
			m_pImage->get_Height(&m_RealSize.cy);
			HiMetricToPixel(&m_RealSize,&m_RealSize);
		}
		
	}
	
	return hr;
}
Exemple #5
0
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);
        }
    }
};