paste a SetClipboardData(CF_DIB) image to powerpoint?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: paste a SetClipboardData(CF_DIB) image to powerpoint?

  1. #1
    Join Date
    Jan 2014
    Posts
    3

    paste a SetClipboardData(CF_DIB) image to powerpoint?

    Hi
    I have a VisualC++ program to display image data to the screen. The data is a 24-bit, RGB bitmap that is properly shown using BitBlt().

    I have a CopyWindow() function that puts the BITMAPINFO structure and RGB image data on the clipboard as a DIB with the SetClipboardData(CF_DIB,...) call.

    My problem happens when I try to paste the image into MS Powerpoint (Office 2010). I've tried Paste and all the options in Paste Special but the image will not appear.

    If I open Paint and do a Paste, the image appears properly in that application. Then I can do a Copy from there and am able to Paste that into Powerpoint.

    How is Paint able to accept the DIB?
    And what is different about how Paste puts that bitmap onto the Clipboard so that Powerpoint can see it?

    Thanks.

    --Ed

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,359

    Re: paste a SetClipboardData(CF_DIB) image to powerpoint?

    Could you show a piece of code?
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2014
    Posts
    3

    Re: paste a SetClipboardData(CF_DIB) image to powerpoint?

    Here is the code.
    (Note that error checking is removed for brevity but I checked the return codes and they all succeed.)

    // ---------------------------------------------
    RGBTRIPLE *m_pUTDispData;
    BITMAPINFO m_bmi;
    CDC *pDC = this->GetDC();
    void *m_pDIBData;

    memset(&m_bmi, 0, sizeof(BITMAPINFO));
    m_bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
    m_bmi.bmiHeader.biWidth = DATA_WIDTH; // width of data buffer in pixels
    m_bmi.bmiHeader.biHeight = -DATA_LENGTH; // length of data buffer in pixels
    m_bmi.bmiHeader.biPlanes = 1;
    m_bmi.bmiHeader.biBitCount = 24;
    m_bmi.bmiHeader.biCompression = BI_RGB;
    m_bmi.bmiHeader.biSizeImage = 0; // can be 0 for BI_RGB bitmaps
    m_bmi.bmiHeader.biXPelsPerMeter = 0;
    m_bmi.bmiHeader.biYPelsPerMeter = 0;
    m_bmi.bmiHeader.biClrImportant = 0; // all colors are required for display
    m_bmi.bmiHeader.biClrUsed = 0;


    m_hDisplayBitmap=CreateDIBSection(pDC->m_hDC, &m_bmi, DIB_RGB_COLORS, &m_pDIBData, NULL, 0);
    m_pUTDispData = (RGBTRIPLE *)m_pDIBData;

    // walk through m_pUTDispData DATA_WIDTH x DATA_LENGTH and fill it with RGB triplets.
    // can be any color - a rainbow, doesn't matter - it successfully BitBlt()s to the screen


    // ---------------------------------------------

    // Later in the CopyWindow() routine... (note that m_pUTDispData and m_bmi are the
    // same variables from above


    HANDLE hData = GlobalAlloc(GHND | GMEM_SHARE,
    sizeof(BITMAPINFO)+m_bmi.bmiHeader.biWidth*m_bmi.bmiHeader.biHeight*3);
    LPVOID pData = (LPVOID)GlobalLock(hData);
    memcpy(pData,&m_bmi,sizeof(BITMAPINFO));
    memcpy((UCHAR *)pData+sizeof(BITMAPINFO), (LPVOID)m_pUTDispData,
    m_bmi.bmiHeader.biWidth*m_bmi.bmiHeader.biHeight*3);
    GlobalUnlock(hData);
    OpenClipboard();
    EmptyClipboard();
    SetClipboardData(CF_DIB, hData);
    CloseClipboard();

    // ---------------------------------------------

  4. #4
    Join Date
    Jan 2014
    Posts
    3

    Re: paste a SetClipboardData(CF_DIB) image to powerpoint?

    ach... too much copy and paste. the "m_bmi.bmiHeader.biHeight = -DATA_LENGTH" line should NOT have the negative sign. my misbehaving code has that number as positive.

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,329

    Re: paste a SetClipboardData(CF_DIB) image to powerpoint?

    Quote Originally Posted by ejbaker View Post
    ach... too much copy and paste. the "m_bmi.bmiHeader.biHeight = -DATA_LENGTH" line should NOT have the negative sign. my misbehaving code has that number as positive.
    When posting code, format it first, click 'Go Adanced', paste the code and then select it and click '#' to have it displayed properly.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center