用MFC做的ActiveX控件,OnDraw时绘制位图,在TestContainer中OK,插入word则绘制失败,请大家指教!
描述:
我做了一个控件,其中绘制一幅位图。用的是有窗口的控件。
放入ActiveX Control Test Container测试时能正确绘制。把控件插入word时则出错!CreateCompatibleDC就失败了。很奇怪! 请各位高手指教!
主要代码如下:
加入了一个位图资源IDB_BITMAP1 :
void CMfcBitmapCtlCtrl::OnDraw(
CDC* pDC, const CRect& rcBounds, const CRect& rcInvalid)
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
BITMAP bm;
bitmap.GetBitmap (&bm);
CPoint size (bm.bmWidth, bm.bmHeight);
pDC->DPtoLP (&size);
CPoint org (0, 0);
pDC->DPtoLP (&org);
CDC dcMem;
int status = dcMem.CreateCompatibleDC (pDC);
if (status == 0) {
AfxMessageBox("CreateCompatibleDC failed!");
return;
}
if (dcMem.m_hDC == NULL) {
AfxMessageBox("hDC is NULL!");
return;
}
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject (bitmap);
dcMem.SetMapMode (pDC->GetMapMode ());
pDC->BitBlt (0, 0, size.x, size.y, &dcMem, org.x, org.y, SRCCOPY);
//pDC->BitBlt (x, y, size.x, size.y, &dcMem, org.x, org.y, SRCAND);
//pDC->TransparentBlt (x, y, size.x, size.y, &dcMem, org.x, org.y, size.x, size.y, RGB(255, 255, 255));//没有这个函数!
dcMem.SelectObject (pOldBitmap);
if (dcMem.m_hDC == NULL)
AfxMessageBox("after hDC is NULL!");
}