Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows MFC clipboard
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 18-Oct-10 8:40am
Edited 18-Oct-10 12:12pm
Shog9100.4K
v3
Comments
Marc A. Brown at 18-Oct-10 14:32pm
   
EDIT: Fixed code block.

1 solution

Rate this: bad
good
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...
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 235
3 Afzaal Ahmad Zeeshan 209
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 18 Oct 2010
Copyright © CodeProject, 1999-2014
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