哪位高手能给在下提供用COM实现画图的例子,简单、复杂的均可.

解决方案 »

  1.   

    只要用了COM就可以吗?
    ActiveX就是COM技术阿,不要说你连ocx控件都没做过哦。。;)
    new->activeX,然后OnDraw里面随便画好了
    -------------------------------
    =fly by=
      

  2.   

    呵呵,做一个简单的例子吧:
    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;
    }
      

  3.   

    补充一下:例子中没有Load图片的部分,但是有这么一句话 CxImage *newima = new CxImage();
    newima->CreateFromHBITMAP(bm);
    这是因为我用了CxImage这个库,很方便。这样可以把dc中的内容方便的保存为CxImage支持的格式。Load部分也一样,你可以用任何其他方式实现,没有什么特别的。
    只是要注意,在COM中因为你没有关联的window,所以用
    HDC dstDC = CreateDC("DISPLAY",NULL,NULL,NULL);
    创建画图用的DC,注意"NULL",呵呵。第一次写的时候老发现画出来的图把背景丢了,黑黑的,就是因为dc没创建对。
      

  4.   

    使用SDK画图函数就可以实现了。