Click to See Complete Forum and Search --> : Re: How do I use IPictureDisp in ATL?


Rob
March 29th, 1999, 01:58 AM
Try sticking the following code in the OnDraw handler:

// Draw the background image

IPicture *pPic;

HBRUSH hBrush;

HPEN hPen, hPenOld;

HBITMAP hBmp, hBmpOld;

HDC hDC;

BOOL bBitBlt;

m_pPicture->QueryInterface(IID_IPicture, (void**)&pPic);

// Get the OLE picture object's handle

if(pPic){

pPic->get_Handle((OLE_HANDLE*)&hBmp);

pPic->Release();

pPic = NULL;

}

// Create a memory DC

hDC = CreateCompatibleDC(di.hdcDraw);

// Select the bitmap into the memory DC

hBmpOld = (HBITMAP)SelectObject(hDC, hBmp);

// Blt the bitmap from the memory dc to the screen

bBitBlt = BitBlt(di.hdcDraw,

di.prcBounds->left,

di.prcBounds->top,

di.prcBounds->right - di.prcBounds->left,

di.prcBounds->bottom - di.prcBounds->top,

hDC,

0,

0,

SRCCOPY);

// Select the old bitmap back into the memory DC

hBmp = (HBITMAP)SelectObject(hDC, hBmpOld);


// Delete the memory DC

DeleteDC(hDC);

rob
March 29th, 1999, 01:58 AM
Try sticking the following code in the OnDraw handler:

// Draw the background image

IPicture *pPic;

HBRUSH hBrush;

HPEN hPen, hPenOld;

HBITMAP hBmp, hBmpOld;

HDC hDC;

BOOL bBitBlt;

m_pPicture->QueryInterface(IID_IPicture, (void**)&pPic);

// Get the OLE picture object's handle

if(pPic){

pPic->get_Handle((OLE_HANDLE*)&hBmp);

pPic->Release();

pPic = NULL;

}

// Create a memory DC

hDC = CreateCompatibleDC(di.hdcDraw);

// Select the bitmap into the memory DC

hBmpOld = (HBITMAP)SelectObject(hDC, hBmp);

// Blt the bitmap from the memory dc to the screen

bBitBlt = BitBlt(di.hdcDraw,

di.prcBounds->left,

di.prcBounds->top,

di.prcBounds->right - di.prcBounds->left,

di.prcBounds->bottom - di.prcBounds->top,

hDC,

0,

0,

SRCCOPY);

// Select the old bitmap back into the memory DC

hBmp = (HBITMAP)SelectObject(hDC, hBmpOld);


// Delete the memory DC

DeleteDC(hDC);

Pete Bassett
November 30th, 1999, 08:47 AM
Yeah. Good code by rob. Another alternative is to use the IPicture methods dirctly


CComQIPtr<IPicture> pIPic(m_pPicture); // where m_pPicture is a pointer to a IPictureDisp interface

if(pIPic)
{
pIPic->Render(di.hdcDraw,blah,blah,blah); // cant remember the exact parameters for this off the top of my head.
}





That should be it. If you look on the MSDN for IPicture interface you'll see the parameters for the Render method. Basically it does exactly what robs code did. If you already have a valid IPictureDisp interface you can use CComQIPtr to make a nice simple (well, simple for client code anyway) QueryInterface for the IPicture interface. Then just check that it worked with the if statement (Its very likely that it will work).
Then use the render method to blt it to the DC.

Hope this helps.

Pete

Final year BSc Computer Science student at University of Brighton, England.