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

📄 pnganimation.cpp

📁 wince下实现开机动画的代码
💻 CPP
字号:
#include <windows.h>
#include <INITGUID.h>
#include "PngAnimation.h"


CPngAnimation::CPngAnimation(void)
{
	m_pImgFactory = NULL;
	m_hBitmapCurrent = 0;
	m_hBitmapOld = 0;
	m_hDCWnd = NULL;
	m_hBitmap = NULL;
	m_hBrush = NULL;
	memset(m_hArrayDC,0,sizeof(m_hArrayDC));
	memset(m_blArrayDC,0,sizeof(m_blArrayDC));
	memset(m_pImageBmp,0,sizeof(m_pImageBmp));
	m_hDCIndex = 0;
	m_nPngIndex = 0;

}

CPngAnimation::~CPngAnimation(void)
{
}

BOOL
CPngAnimation::PngAnimationInit(HWND hWnd)
{
	::InitializeCriticalSection(&m_sec);
	CoInitializeEx(NULL, COINIT_MULTITHREADED);

	if(SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory, NULL,
									CLSCTX_INPROC_SERVER,
									IID_IImagingFactory,
									(void**)&m_pImgFactory)))
	{
		
		m_hDCWnd = ::GetDC(hWnd);
		m_hBitmap = CreateCompatibleBitmap (m_hDCWnd, 800, 270);
		for(m_hDCIndex=0;m_hDCIndex<THEAD_NUM;m_hDCIndex++)
		{
			m_hArrayDC[m_hDCIndex] = ::CreateCompatibleDC(m_hDCWnd);
			if(m_hArrayDC[m_hDCIndex] == NULL)
			{
				info(TEXT("Not Enough Memory to CreateCompatibleDC:%d!\r\n"),m_hDCIndex);
				return false;
			}
		}

		m_hBrush = ::CreateSolidBrush(RGB(0,16,57));

	
		return TRUE;
	}
	else
	{
		return FALSE;
	}


}

void
CPngAnimation::PngAnimationDeinit(void)
{
	static int i = 0;

	if(m_pImgFactory)
	{
		m_pImgFactory->Release();
		m_pImgFactory = NULL;
	}
	if(m_hBrush)
	{
		::DeleteObject(m_hBrush);
		m_hBrush = NULL;

	}

	if(m_hBitmap)
	{
		DeleteObject(m_hBitmap);
		m_hBitmap = NULL;
	}

	for(i=0;i<THEAD_NUM;i++)
		{
			if(m_hArrayDC[i] != NULL)
			{
				::DeleteDC(m_hArrayDC[i]);
				m_hArrayDC[i] = NULL;
			}
		}

	for(i=0;i<THEAD_NUM;i++)
		{
			if(m_pImageBmp[i] != NULL)
			{
				m_pImageBmp[i]->Release();
				m_pImageBmp[i] = NULL;
			}
		}
	if(m_hDCWnd)
	{
		DeleteDC(m_hDCWnd);
		m_hDCWnd = NULL;
	}
	CoUninitialize();
	::DeleteCriticalSection(&m_sec);

	return;

}
BOOL
CPngAnimation::PngDraw(unsigned int indexPng, unsigned int indexHDC)
{
	RECT		rc={0,0,800,270};
	HBITMAP		hOldBitmap;
	static BOOL bFlags;
	//	ImageInfo	imageInfo;
	m_nPngIndex = indexPng;
	DWORD dwStart = ::GetTickCount();

	wchar_t lpFileName[50] = {0};
	wsprintf(lpFileName,DATA_PATH L"PowerOn\\On_%04d.png",m_nPngIndex);

	HRESULT hResult = m_pImgFactory->CreateImageFromFile(lpFileName, &m_pImageBmp[indexHDC]);

	if((SUCCEEDED(hResult))/* && (SUCCEEDED(pImageBmp->GetImageInfo(&imageInfo)))*/)
	{
		Lock();
		bFlags = GetFlags(indexHDC);
		UnLock();

		if(bFlags == FALSE)
		{

			hOldBitmap = (HBITMAP)SelectObject(m_hArrayDC[indexHDC],m_hBitmap);
			FillRect(m_hArrayDC[indexHDC],&rc,m_hBrush);

			m_pImageBmp[indexHDC]->Draw(m_hArrayDC[indexHDC], &rc,NULL);
			::SelectObject(m_hArrayDC[indexHDC],hOldBitmap);
		Lock();
			m_blArrayDC[indexHDC] = TRUE;
		UnLock();
		}

	}
	DWORD dwCurrent = ::GetTickCount();
	info(TEXT("Png Draw %s Time:%d \r\n"),lpFileName, (dwCurrent - dwStart));


	return TRUE;
}

BOOL
CPngAnimation::PngDisplay(unsigned int indexHDC)
{
//	IImage *pImageBmp = NULL;
//	ImageInfo	imageInfo;
	HBITMAP		hOldBitmap;

		m_hDCIndex = indexHDC;
		while(m_blArrayDC[m_hDCIndex] == FALSE);
		if(m_blArrayDC[m_hDCIndex] == TRUE)
		{
			info(TEXT("Png Display : %d \r\n"),indexHDC);
			hOldBitmap = (HBITMAP)SelectObject(m_hArrayDC[m_hDCIndex],m_hBitmap);
			BitBlt(m_hDCWnd, 0, 0, 800, 270, m_hArrayDC[indexHDC], 0, 0, SRCCOPY);
			::SelectObject(m_hArrayDC[m_hDCIndex],hOldBitmap);//			m_blArrayDC[m_hDCIndex] = FALSE;

			m_blArrayDC[m_hDCIndex] = FALSE;
		}
		return TRUE;
}

⌨️ 快捷键说明

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