TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT KUZBA
from: ALBERTO MONTEIRO
date: 1997-11-30 19:31:00
subject: Save Bitmap in M$C/Part 3

//
// This is Part 3
//
// In Part 1 and Part 2, I put the routines (taken from
// M$C help archives) that save a Bitmap (given by its
// handle) to a File (given by its handle)
//
// This routine copies the CDC * associated to the Window
// to the CBitmap class
//
// Of course, I suppose that after invoking this routine,
// it will be possible to save the bitmap to a file
//
#include "stdafx.h"
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
                  HBITMAP hBMP, HDC hDC); // Part 1
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
// Part 2
int CWnd_to_CBitmap(CWnd & cwnd, CBitmap & cbmp)
{
  CDC *pDC = cwnd.GetDC();
  CDC pDC1;
  CBitmap *old_bmp;
  BITMAP bmp;
  if (pDC1.CreateCompatibleDC(pDC) == FALSE) {
    AfxMessageBox("Erro em CreateCompatibleDC");
    return -1;
  }
  CRect rt;
  cwnd.GetClientRect(&rt);
  if (rt.right & 1)
    rt.right++;     // numero par
  if (cbmp.CreateCompatibleBitmap(pDC, rt.right, rt.bottom) == 0) {
    AfxMessageBox("Erro em CreateCompatibleBitmap");
    return -1;
  }
/* Select the bitmaps into the compatible DC. */
  if ((old_bmp = pDC1.SelectObject(&cbmp)) == NULL) {
    AfxMessageBox("Erro em SelectObject");
    return -1;
  }
        /*
         * Copy color data for the entire display into a
         * bitmap that is selected into a compatible DC.
         */
  cbmp.GetBitmap(&bmp);
  if (pDC1.BitBlt(0, 0, bmp.bmWidth, bmp.bmHeight,
      pDC, 0, 0, SRCCOPY) == FALSE) {
    AfxMessageBox("Erro em BitBlt");
    return -1;
  }
  pDC1.SelectObject(old_bmp);
  return 1;
}
---
 þ SLMR 2.1a þ Slimy ... yet satisfying (Timon)
--- FMail/386 1.02
---------------
* Origin: CentroIn! +55-21-205-0281, 41 lines, 24h, RJ/Brazil (4:802/21)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.