Click here to Skip to main content
13,048,805 members (85,449 online)
Rate this:
Please Sign up or sign in to vote.
I am trying to copy the image to clipboard. I am using the following code.
void test::OnEditCopyImage()     // Copy to the Clipboard.
    bool clipboardAcceptedData = true;
    // Capture the window to a bitmap.
    COXScreenGrabber ScreenGrabber; 
    RECT rect;
    GetParent()->GetWindowRect(&rect);  // get the rect of the frame, not just the graph
    COXDIB* pDib = ScreenGrabber.GetGrabDIB();
    VERIFY(EmptyClipboard()):// Remove the current Clipboard contents & reassign ownership.
    if (::SetClipboardData(CF_DIB, pDib->m_hDIB)==NULL)
        clipboardAcceptedData = false;
    //keep the bitmap 'alive', the clipboard now owns it.
    // Set the handle to NULL so that the destructor does not free the memory.
    if ( clipboardAcceptedData == true )
        pDib->m_hDIB = NULL; 

But the selected menu item 'COPY Image to ClipBoard' also appears on the image. It happens only when I run the program on Windows Vista/Windows 7. Works fine on WINDOWS XP. Can anyone help?
Posted 18-Oct-10 7:40am
Updated 18-Oct-10 11:12am
Marc A. Brown 18-Oct-10 14:32pm
EDIT: Fixed code block.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Gotta assume that the problem is in COXScreenGrabber, not this code. If it's actually grabbing part of the screen buffer instead of rendering your window, then anything above it will tend to get caught... Including a quickly-fading image of the selected menu item.

If possible, investigate the options for whatever library you're using; perhaps there's a way to target a specific window. Failing that, set a short (1-2 second) timer after the user triggers the menu item, and when it expires then take the screenshot. This last method is used by many screengrabbers to avoid just such a problem...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 18 Oct 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100