CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    19

    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);

  2. #2
    Join Date
    Apr 1999
    Posts
    19

    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);

  3. #3
    Join Date
    Nov 1999
    Location
    Brighton, England. UK
    Posts
    148

    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
  •  





Click Here to Expand Forum to Full Width

Featured