// prepare the new document CxImage *newima = new CxImage(); newima->CreateFromHBITMAP(bm); ::ReleaseDC(NULL,dstDC); if (!newima->IsValid()) { // Record the Error. ATLTRACE(_T("创建图像失败。\r\n")); } else *pbResult = TRUE; delete m_image; m_image = newima;
ActiveX就是COM技术阿,不要说你连ocx控件都没做过哦。。;)
new->activeX,然后OnDraw里面随便画好了
-------------------------------
=fly by=
Markup方法提供在一个指定的图片中指定位置写上注释。
我比较土,直接在com中用MFC,省点儿事。
在内存中先建立一个dc,把bitmap读入,然后在这个dc上textout,当然你可以画个大饼什么的(还没吃早点)...
STDMETHODIMP CMarkupPic::Markup(long x, long y, BSTR sComment, VARIANT_BOOL* pbResult)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
*pbResult = FALSE;
if ( (!m_image) || (!m_image->IsValid()))
{
ATLTRACE(_T("Markup 失败。没有载入图片文件。\r\n"));
return S_OK;
} CPoint myPoint;
myPoint.x = x;
myPoint.y = y; CString strComment(sComment); int iWidth = m_image->GetWidth();
int iHeight = m_image->GetHeight(); HDC dstDC = CreateDC("DISPLAY",NULL,NULL,NULL);
HDC memDC = CreateCompatibleDC(dstDC);
HBITMAP bm = CreateCompatibleBitmap(dstDC,
GetDeviceCaps(dstDC, HORZRES),
GetDeviceCaps(dstDC, VERTRES));
// HBITMAP bm = ::CreateCompatibleBitmap(memDC,iWidth,iHeight);
if (!(HBITMAP)::SelectObject(memDC,bm))
{
ATLTRACE(_T("SelectObject Error.\r\n"));
return S_OK;
} m_image->Draw(memDC,0,0,iWidth,iHeight); CDC myDC;
myDC.Attach(memDC);
myDC.SetBkMode(TRANSPARENT);
myDC.TextOut(myPoint.x,myPoint.y,strComment);
// prepare the new document
CxImage *newima = new CxImage();
newima->CreateFromHBITMAP(bm); ::ReleaseDC(NULL,dstDC); if (!newima->IsValid())
{
// Record the Error.
ATLTRACE(_T("创建图像失败。\r\n"));
}
else
*pbResult = TRUE;
delete m_image;
m_image = newima;
return S_OK;
}
newima->CreateFromHBITMAP(bm);
这是因为我用了CxImage这个库,很方便。这样可以把dc中的内容方便的保存为CxImage支持的格式。Load部分也一样,你可以用任何其他方式实现,没有什么特别的。
只是要注意,在COM中因为你没有关联的window,所以用
HDC dstDC = CreateDC("DISPLAY",NULL,NULL,NULL);
创建画图用的DC,注意"NULL",呵呵。第一次写的时候老发现画出来的图把背景丢了,黑黑的,就是因为dc没创建对。