|
-
March 29th, 1999, 02:58 AM
#1
Re: How do I use IPictureDisp in ATL?
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);
-
March 29th, 1999, 02:58 AM
#2
Re: How do I use IPictureDisp in ATL?
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);
-
November 30th, 1999, 09:47 AM
#3
Re: How do I use IPictureDisp in ATL?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|