OpenGL Programming for Windows MFC


10. Copy to clipboard


10.1 OnEditCopy をオーバライドし以下の行追加

void CXxxView::OnEditCopy() 
{

    CBitmap     Bmp;            // GDI bitmap
    CDC         MemDC;          // Handle to a memory DC
    CRect     rect;             // For storing the size of the window

    MemDC.CreateCompatibleDC(m_pDC); // Create the memory DC.
 
    GetWindowRect(rect);         // Get the size of the window
    
    Bmp.CreateCompatibleBitmap(m_pDC, rect.Width(),rect.Height() );
    
    CBitmap* pOldBitmap = MemDC.SelectObject(&Bmp); // Keep the old bitmap

    RenderingToBitmap(MemDC.m_hDC, rect.Width(), rect.Height()) ;

    // Copy to Clipboard

    AfxGetApp()->m_pMainWnd->OpenClipboard() ;
    EmptyClipboard() ;
    SetClipboardData (CF_BITMAP, Bmp.m_hObject ) ;
    Bmp.Detach() ;
    CloseClipboard () ;

    MemDC.SelectObject(pOldBitmap);
    MemDC.DeleteDC() ;

}
Overrid OnEditCopy of CXXXView by Class Wizard. Then, add the above line.


prev next