OpenGL Programming for Windows MFC


12. Copy to bitmap file


12.1 Bitmap save の Menu(OnBitmapSave)追加


12.2 OnBitmapSave をオーバライドし以下の行追加

void CXxxView::OnBitmapSave()
{

    CString     PathName ;
    char        *FileName ;

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

    // Get bmp file name 

    CFileDialog *FileDia = new CFileDialog(FALSE,"bmp",NULL,OFN_OVERWRITEPROMPT,
                                           "Windows bitmap file (*.bmp)|*.bmp||",NULL) ;
    if (FileDia->DoModal() != IDOK) {
        delete  FileDia ;
        return ;
    }

    PathName = FileDia->GetPathName() ;
    FileName = PathName.GetBuffer(256) ;

    // Rendering to bitmap 

    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 Bitmap file

    pBmpInf = CreateBitmapInfoStruct(Bmp) ;

    CreateBMPFile(FileName, pBmpInf, Bmp, MemDC.m_hDC) ;

    delete  FileDia ;

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

}

CreateBitmapInfoStruct , CreateBMPFile については VC++ -> Help を参照

Refer to VC++ -> Help for "CreateBitmapInfoStruct", "CreateBMPFile".


prev next