⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wzdbtmap.cpp

📁 《vc++扩展编程实例》源码。运用Visual C++ 5.0或6.0的高级编程技巧
💻 CPP
字号:
// WzdBtmap.cpp : implementation of the CWzdBitmap class
//

#include "stdafx.h"
#include "WzdBtmap.h"

/////////////////////////////////////////////////////////////////////////////
// CWzdBitmap

IMPLEMENT_DYNAMIC(CWzdBitmap, CBitmap)


CWzdBitmap::CWzdBitmap()
{
	m_pPalette=NULL;
}

CWzdBitmap::~CWzdBitmap()
{
	if (m_pPalette)
	{
		delete m_pPalette;
	}
}

void CWzdBitmap::Capture(CRect &rect)
{
// cleanup old captures
	if (m_pPalette)
	{
		DeleteObject();
		delete m_pPalette;
	}

// save width and height
	m_nWidth=rect.Width();
	m_nHeight=rect.Height();

////////////////////////////////////////
// copy screen image into a bitmap object
////////////////////////////////////////

	// create a device context that accesses the whole screen
	CDC dcScreen;
    dcScreen.CreateDC("DISPLAY", NULL, NULL, NULL);

	// create an empty bitmap in memory
	CDC dcMem;
    dcMem.CreateCompatibleDC(&dcScreen);
    CreateCompatibleBitmap(&dcScreen, m_nWidth, m_nHeight);
    dcMem.SelectObject(this);

    // copy screen into empty bitmap
    dcMem.BitBlt(0,0,m_nWidth,m_nHeight,&dcScreen,rect.left,rect.top,SRCCOPY);

// this bitmap is worthless without the current system palette, so...

///////////////////////////////////////////
// save system palette in this bitmap's palette
///////////////////////////////////////////

	// create an empty logical palette that's big enough to hold all the colors
    int nColors = (1 << (dcScreen.GetDeviceCaps(BITSPIXEL) * 
    			dcScreen.GetDeviceCaps(PLANES)));
	LOGPALETTE *pLogPal = (LOGPALETTE *)new BYTE[
		sizeof(LOGPALETTE) + (nColors * sizeof(PALETTEENTRY))];

	// initialize this empty palette's header
	pLogPal->palVersion    = 0x300;
	pLogPal->palNumEntries = nColors;

	// load this empty palette with the system palette's colors
    ::GetSystemPaletteEntries(dcScreen.m_hDC, 0, nColors,
            (LPPALETTEENTRY)(pLogPal->palPalEntry));

	// create the palette with this logical palette
	m_pPalette=new CPalette;
	m_pPalette->CreatePalette(pLogPal);

    // clean up
	delete []pLogPal;
	dcMem.DeleteDC();
	dcScreen.DeleteDC();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -