OleDraw to a memory bitmap

closed account (DSyhURfi)
I've been banging my head against this question for a little while now, and it's starting to hurt, so I was hoping someone could help me.

We have OLE/COM container behavior implemented in our application, and I am trying to work with OleDraw/IViewObject->draw to draw the embedded object/control on screen. Because of redraw issues, I need to get the object representation into memory so I can draw it using an API (Qt, but that shouldn't really enter into this question.) So I put together the following routine to draw the picture into a memory bitmap. This is partly working, and I get a image that is clearly a representation of the content, but it looks like I am having some kind of issue with the alpha channel of the image data. Specifically when I embed an excel spreadsheet into my container, and call this code, I get a bitmap where all the information in the original that should be black is not visible, and when I write that bitmap out to a file, it looks like the background of all the cells is black.
I'm pretty sure that this has something to do with masking off the parts of the image that should be transparent, and something that I read somewhere about how Bitmaps don't really deal with transparency, but I really don't have a clue how to resolve this. If someone could enlighten me, I would appreciate it.

thanks,

SteveL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
//
//
QPixmap EEmbedObject::ObjectImage()
{
	QPixmap p;
	SIZE	picSize; 
	HDC		dc;
	RECT	r;
	RECTL	rec;
	UINT	oldAlign;
	long	hr;
	HDC		tmpDC  = GetDC((HWND) winId());
	HDC		memDC  = CreateCompatibleDC(tmpDC);
	HBITMAP hBmp   = CreateCompatibleBitmap(tmpDC, width(), height());
	HBITMAP oldBmp = (HBITMAP)SelectObject(memDC, hBmp);
	
	SetRect(&r, 0, 0, width(), height());
	rec.top		= r.top;
	rec.left	= r.left;
	rec.bottom	= r.bottom;
	rec.right	= r.right;

	if (m_pIViewObject == NULL)
		hr = m_pObj->QueryInterface(IID_IViewObject, (void **) &m_pIViewObject);

	//SetBkColor(memDC, RGB(255, 255, 255));
	//SetTextColor(memDC, RGB(0, 0, 0));
	//SetBkMode(memDC, OPAQUE);

	oldAlign = SetTextAlign(memDC, TA_TOP);

	hr = m_pIViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, memDC, &rec, NULL, NULL, 0);
	//hr = OleDraw(m_pObj, DVASPECT_CONTENT, memDC, &r);

	SetTextAlign(memDC, oldAlign);
	SelectObject(memDC, oldBmp);

	// JSL - code to write out the BMP to a file, so I can see it before the conversion.
	PBITMAPINFO pbi = CreateBitmapInfoStruct((HWND) gMainWindow->winId(), hBmp);
	CreateBMPFile((HWND) gMainWindow->winId(), (LPTSTR) L"oleDrawBitmap.bmp", pbi, hBmp, tmpDC);

	p = QtWin::fromHBITMAP(hBmp, QtWin::HBitmapAlpha);
	p.save(QString("oleDrawPixmap.bmp"));
    
	DeleteObject(hBmp);
	DeleteDC(memDC); 
	ReleaseDC((HWND) winId(), tmpDC);

	return(p);
}
Topic archived. No new replies allowed.