Windows界面编程第十一篇 位图显示特效 随机积木效果

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696724

欢迎关注微博:http://weibo.com/MoreWindows

Windows界面编程之位图显示特效系列目录:

1. Windows界面编程第九篇位图显示特效交错效果》

http://blog.csdn.net/morewindows/article/details/8696720

2. Windows界面编程第十篇位图显示特效百叶窗效果》

http://blog.csdn.net/morewindows/article/details/8696722

3. Windows界面编程第十一篇位图显示特效随机积木效果》

http://blog.csdn.net/morewindows/article/details/8696724

4. Windows界面编程第十二篇位图显示特效飞入效果与伸展效果》

http://blog.csdn.net/morewindows/article/details/8696726

5. Windows界面编程第十三篇位图显示特效合集》

http://blog.csdn.net/morewindows/article/details/8696730

 

本篇《Windows界面编程第十一篇位图显示特效随机积木效果》将讲解位图的随机积木显示效果。如下图所示

(图片不能打开,请访问http://blog.csdn.net/morewindows/article/details/8696724):

 

      在程序设计上,随机积木效果是最简单的啦,只要一格一格的显示出整个位置即可:

// 随机积木
//《Windows界面编程第十一篇 位图显示特效 随机积木效果》
//http://blog.csdn.net/morewindows/article/details/8696724
void AnimateDraw_RandomBlocks(HDC hdc, HDC hdcMem, int nWidth, int nHeight, UINT nIntervalTime = 15,
							  int nRowBlocks = 10, int nColBlocks = 10)
{
	int nStepRow, nStepCol, nDisplayCount;
	int nSumBlocks = nRowBlocks * nColBlocks;
	bool *pFlagArray = new bool[nSumBlocks];
	memset(pFlagArray, 0, sizeof(bool) * nSumBlocks);

	nStepRow = nWidth / nRowBlocks;
	nStepCol = nHeight / nColBlocks;
	srand((unsigned)time(NULL));
	nDisplayCount = 0; //已显示方格个数
	while (true) 
	{ 
		int row = rand() % nRowBlocks; 
		int col = rand() % nColBlocks; 
		if (pFlagArray[row * nColBlocks + col]) 
			continue;
		pFlagArray[row * nColBlocks + col] = true;

		BitBlt(hdc, row * nStepRow, col * nStepCol, nStepRow, nStepCol, 
			hdcMem, row * nStepRow, col * nStepCol, SRCCOPY);
		nDisplayCount++;
		if (nDisplayCount >= nSumBlocks)
			break;
		Sleep(nIntervalTime); 
	}
	BitBlt(hdc, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
}

完整的程序在《Windows界面编程第十三篇位图显示特效合集》

http://blog.csdn.net/morewindows/article/details/8696730

下一篇《Windows界面编程第十二篇位图显示特效飞入效果与伸展效果》将讲解位图的飞入效果与伸展效果。

地址:http://blog.csdn.net/morewindows/article/details/8696726

 转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696724

欢迎关注微博:http://weibo.com/MoreWindows

posted @ 2013-03-25 13:26  xinyuyuanm  阅读(182)  评论(0编辑  收藏  举报