我做了一个控件,其中绘制一幅位图。用的是有窗口的控件。 放入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!");
}
加入了一个位图资源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!");
}
解决方案 »
- vc下,创建自己定义的CListCtrl控件时失败了,请帮忙解决,谢谢了
- 有关多线程和消息的问题,请教高手!
- 关于findwindowex的问题,原先在系统区发了没人回,到这里再发一下
- 关于listctrl的问题一个~
- 如何寻找内存泄漏,memory leaks
- ListCtrl控件的问题
- 谁知道如何在www.ieee.com上下载到全文,我是公网的用户!我给500分,不够的话,再给...谢谢!
- 单机程序用什么数据库好?
- 大家有没有好一点的比较两个文件是否相同的想法呢?
- 高手请我个帮忙
- 搜索引擎的机器人的原理是什么?
- <<VC++/Turbo c 串口通信编程实践>>中关于求校验和的一些基础问题~~
Dim ocxCtrl As Object
Set ocxCtrl = ActiveDocument.Shapes.AddOLEControl("MfcBitmapCtl.MfcBitmapCtlCtrl.1", , , , , Selection.Range)
ocxCtrl.WrapFormat.Type = wdWrapNone
Debug.Print ActiveDocument.Name
End Sub
{
return COleControl::GetControlFlags() | windowlessActivate ;
}很郁闷,请大家救我!如果不检测返回值也不弹对话框,则Debug版本会assert失败,而release版本好像是正常的,至少能画出图,但这肯定隐藏着问题。实际上当我想绘制透明控件时,放入word中就没效果。实际上也是CreateCompatibleDC就失败了!
在design mode 中CreateCompatibleDC失败
design mode时CreateCompatibleDC失败,而user mode时word直接崩溃了!该怎么改呢?能说的具体些吗?我的程序哪里有问题呢?我用的插入到word的代码如下(先是design mode,后来切换到user mode):
Sub test()
If ActiveDocument.FormsDesign = False Then
ActiveDocument.ToggleFormsDesign '切换到FormDesign
CommandBars("Control Toolbox").Visible = False
End If Dim ocxCtrl As Object
Set ocxCtrl = ActiveDocument.Shapes.AddOLEControl("MfcBitmapCtl.MfcBitmapCtlCtrl.1", , , , , Selection.Range)
'这时是design mode
ocxCtrl.Visible = msoFalse
ocxCtrl.ZOrder msoSendBehindText
ocxCtrl.WrapFormat.Type = wdWrapNone
If ActiveDocument.FormsDesign = True Then
ActiveDocument.ToggleFormsDesign
End If
CommandBars("Control Toolbox").Visible = False
ocxCtrl.Visible = msoTrue
'这时是user mode
End Sub