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

📄 memdc.cpp

📁 evc MFC下实现文字滚动效果 AU1250下通过测试
💻 CPP
字号:
#include "stdafx.h"
#include "MemDC.h"

//----------------------------------------------------------------------
//Description:
//	Construction
//-----------------------------------------------------------------------
CMemDC::CMemDC(void):
m_hdcMem(NULL),
m_hBitmap(NULL),
m_hOldSel(NULL)
{
	memset(&m_Size,0,sizeof(m_Size));
}

//----------------------------------------------------------------------
//Description:
//	Destruction
//-----------------------------------------------------------------------
CMemDC::~CMemDC(void)
{
}


//----------------------------------------------------------------------
//Description:
//	Create the memory DC. After succeed in calling the function ,you should
//call Delete() to release resource.
//
//Parameters:
//	hdc : [in] Handle to an existing device context. 
//	pSize : [in] The size of the memory DC to create.
//		If NULL, the function uses the screen size.
//-----------------------------------------------------------------------
BOOL CMemDC::Create(HDC hdc, const SIZE *pSize)
{
	BOOL bResult = FALSE;

	if(hdc == NULL || m_hdcMem != NULL)
	{
		goto EXIT;
	}

	if(pSize != NULL)
	{
		m_Size = *pSize;
	}
	else
	{
		m_Size.cx = GetSystemMetrics(SM_CXSCREEN);
		m_Size.cy = GetSystemMetrics(SM_CYSCREEN);
	}

	//Create a DC that matches the device
	m_hdcMem = CreateCompatibleDC(hdc);
	if(m_hdcMem == NULL)
	{
		goto EXIT;
	}

	m_hBitmap = CreateCompatibleBitmap(hdc,m_Size.cx,m_Size.cy);
	if(m_hBitmap == NULL)
	{
		goto EXIT;
	}

	//Select the bitmap into to the compatible device context
	m_hOldSel = SelectObject(m_hdcMem,m_hBitmap);

	bResult = TRUE;

EXIT:
	if(bResult == FALSE)
	{
		DeleteObject(m_hBitmap);
		m_hBitmap = NULL;
		
		DeleteDC(m_hdcMem);
		m_hdcMem = NULL;
	}

	return bResult;
}



//----------------------------------------------------------------------
//Description:
//	Delete the memory DC
//
//-----------------------------------------------------------------------
BOOL CMemDC::Delete(void)
{
	if(m_hdcMem == NULL || m_hOldSel == NULL || m_hBitmap == NULL)
	{
		return FALSE;
	}

	//Restore original bitmap selection and destroy the memory DC
	SelectObject(m_hdcMem,m_hOldSel);
	DeleteObject(m_hBitmap);	
	DeleteDC(m_hdcMem);

	m_hdcMem = NULL;
	m_hOldSel = NULL;
	m_hBitmap = NULL;

	memset(&m_Size,0,sizeof(m_Size));

	return TRUE;
}


//----------------------------------------------------------------------
//Description:
//	Get the handle of the memory DC. You COULDN'T release the DC by window api funtion ReleaseDC() !
//Instead, you should call CMemDC::Delete().
//	Null incdicates failed
//
//-----------------------------------------------------------------------
HDC CMemDC::GetDC(void)
{
	return m_hdcMem;
}

//----------------------------------------------------------------------
//Description:
//	Get the width of the memory DC
//
//-----------------------------------------------------------------------
LONG CMemDC::GetWidth(void)
{
	return m_Size.cx;
}

//----------------------------------------------------------------------
//Description:
//	Get the height of the memory DC
//
//-----------------------------------------------------------------------
LONG CMemDC::GetHeight(void)
{
	return m_Size.cy;
}

//----------------------------------------------------------------------
//Description:
//	Check the memory DC. 
//
//Parameters:
//	NULL
//
//Return Values:
//	TRUE - ready.
//	FALSE - Not ready.
//
//-----------------------------------------------------------------------
BOOL CMemDC::IsOK(void)
{
	return (m_hdcMem != NULL);
}

⌨️ 快捷键说明

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