我现在有一个HBITMAP对象m_pBitMap
类中定义的变量:
HBITMAP m_pBitMap;
IPictureDisp* m_pImage;
PICTDESC desc;ATL中代码:STDMETHODIMP CMyOcx::get_Image(IPictureDisp **pVal)
{
// TODO: Add your implementation code here

if (!m_pBitMap)
{
*pVal = NULL;
return S_OK;
} desc.cbSizeofstruct = sizeof(PICTDESC);
desc.picType = PICTYPE_BITMAP;
desc.bmp.hpal = 0; // True color
    desc.bmp.hbitmap = m_pBitMap;    ::OleCreatePictureIndirect( &desc, 
IID_IPictureDisp, 
TRUE, 
(void**)&m_pImage); *pVal = m_pImage;
(*pVal)->AddRef();

return S_OK;
}
我在VB中调用,可以得到Image属性的高度和宽度
可是我如何将这个Image属性绘制到我VB的Picture控件上?
我用PaintPicture没反应

Dim x as IPictureDisp
    Set x = myOcx.Image
    Picture1.Picture = x
也没反应请问问题可能出在哪?

解决方案 »

  1.   

    我查了下,说还要做点工作才行After OleCreatePictureIndirect finishes
    doing its thing, you still have to do a bit
    more work before you have a usable picture
    object. The OleCreatePictureIndirect function
    does not create or initialize an hDC for
    the newly created picture object. That’s
    somewhat inconvenient, but understandable
    because the function really has no way
    of knowing what DC would be appropriate.
    So, a few more lines of code are required to
    finish initializing the picture object:
    HDC hdcpict =
    CreateCompatibleDC(dc);
    HBITMAP hbmold =(HBITMAP)::SelectObject(
    hdcpict, pd.bmp.hbitmap);
    IPict->SelectPicture(
    hdcpict, NULL, NULL );
    At this point, you have created a fully initialized
    picture object you can pass to VB or
    other automation clients.