//
// 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)
|