Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
      
    mainFrame->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
    GetParent()->GetWindowRect(&rect);  // get the rect of the frame, not just the graph
    
    ScreenGrabber.GrabRectangle(rect);
    COXDIB* pDib = ScreenGrabber.GetGrabDIB();
   
    VERIFY(OpenClipboard());
    VERIFY(EmptyClipboard()):// Remove the current Clipboard contents & reassign ownership.
    if (::SetClipboardData(CF_DIB, pDib->m_hDIB)==NULL)
    {
        AfxMessageBox(IDS_STRING123);
        clipboardAcceptedData = false;
    }
    
    CloseClipboard();
    //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
Updated 18-Oct-10 11:12am
v3
Comments
Marc A. Brown 18-Oct-10 14:32pm    
EDIT: Fixed code block.

1 solution

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...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900