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

 

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

 

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

// 随机积木
//《Windows界面编程第十一篇 位图显示特效 随机积木效果》
//javascript:void(0)
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);
}


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