C语言编程学习打造表白神器:亲爱的让我们相爱在一起

这个程序是专门为2017情人节而开发的,是在之前程序的基础上,进行的总结和改进,使界面变得更加酷炫的梦幻,还增加了些许的浪漫气息,很适合表白和装逼使用。

由于这个程序酷炫,而且实现原理和编码都不难,。如果你已经学过C或C++,那么只要跟着教程一步步操作,就完全可以在两三天之内理解并实现出这个小程序。那么2018年5月20日快到了,你完全可以自己实现一个这样的小程序。

效果:

注意点:

此图是动态图,以实物为准,画是动态,蝴蝶也是动态的。

功能:

1.窗口透明;

2.显示位图;

开发环境:VS2013

开发语言:MFC + C/C++

主要代码:

/*

设计想法是:

2. 然后再顺时针方向依次显示心形花儿;

3. 在心形图案的中心,显示一朵更大的花儿;

4. 绘制蝴蝶飞舞;

5. 在心形图案的下方显示祝福语和署名;

*/

int i = 0, j = 0;

// 花儿图片参数

int iElapseSlow = 2000; // 停顿时间间隔

int iElapseFast = 1500; // 停顿时间间隔

int iFirstFlowerWidth = 450;

int iFirstFlowerHeight = 356;

int iFirstNumFrame = 21;

int iFirstNumFlowering = 7;

int iSecondFlowerWidth = 250;

int iSecondFlowerHeight = 198;

int iSecondNumFrame = 25;

int iSecondNumFlowering = 8;

// 获取屏幕宽和高

int iWidth = ::GetSystemMetrics(SM_CXSCREEN);

int iHeight = ::GetSystemMetrics(SM_CYSCREEN);

// 初始化

for (i = 0; i

{

m_myFlower[i].myFlower.Init(IDB_BITMAP2, 0, 0, iSecondNumFrame, iSecondNumFlowering);

m_myFlower[i].myFlower.SetWidthHeight(iSecondFlowerWidth, iSecondFlowerHeight);

}

// 设置显示坐标位置

m_myFlower[0].myFlower.SetPosXY(0, 0);

m_myFlower[1].myFlower.SetPosXY((iWidth - iSecondFlowerWidth), 0);

m_myFlower[2].myFlower.SetPosXY((iWidth - iSecondFlowerWidth), (iHeight - iSecondFlowerHeight));

m_myFlower[3].myFlower.SetPosXY(0, (iHeight - iSecondFlowerHeight));

// 显示

for (i = 0; i

{

m_myFlower[i].bExist = TRUE;

Sleep(iElapseSlow); // 停顿

}

// 2. 然后再顺时针方向依次显示心形花儿

/*

将屏幕一部分看成是8x8的格子,则心形图案为:

* * * * * * * *

* O O * O O * *

O * * O * * O *

O * * * * * O *

* O * * * O * *

* * O * O * * *

* * * O * * * *

* * * * * * * *

由于电脑屏幕大都是长方形,若屏幕高为iScreenHeight,

则我们就截取iScreenHeight x iScreenHeight 的区域

划分为8x8的格子!

各个心形的坐标位置都可以计算出来!

先绘制左半边,在绘制右半边

*/

// 计算

int iPerImageWidth = iHeight / 8;

int iPerImageHeight = iHeight / 8;

int x = ((iWidth - iHeight) / 2) + (iPerImageWidth / 2);

int y = 0;

// 初始化

for (i = 4; i

{

m_myFlower[i].myFlower.Init(IDB_BITMAP1, x, y, iFirstNumFrame, iFirstNumFlowering);

m_myFlower[i].myFlower.SetWidthHeight(iPerImageWidth, iPerImageHeight);

}

// 设置显示坐标位置

m_myFlower[4].myFlower.SetPosXY((x + 3*iPerImageWidth), (y + 2*iPerImageHeight));

m_myFlower[5].myFlower.SetPosXY((x + 2 * iPerImageWidth), (y + 1 * iPerImageHeight));

m_myFlower[6].myFlower.SetPosXY((x + 1 * iPerImageWidth), (y + 1 * iPerImageHeight));

m_myFlower[7].myFlower.SetPosXY((x + 0 * iPerImageWidth), (y + 2 * iPerImageHeight));

m_myFlower[8].myFlower.SetPosXY((x + 0 * iPerImageWidth), (y + 3 * iPerImageHeight));

m_myFlower[9].myFlower.SetPosXY((x + 1 * iPerImageWidth), (y + 4 * iPerImageHeight));

m_myFlower[10].myFlower.SetPosXY((x + 2 * iPerImageWidth), (y + 5 * iPerImageHeight));

m_myFlower[11].myFlower.SetPosXY((x + 3 * iPerImageWidth), (y + 6 * iPerImageHeight));

m_myFlower[12].myFlower.SetPosXY((x + 4 * iPerImageWidth), (y + 1 * iPerImageHeight));

m_myFlower[13].myFlower.SetPosXY((x + 5 * iPerImageWidth), (y + 1 * iPerImageHeight));

m_myFlower[14].myFlower.SetPosXY((x + 6 * iPerImageWidth), (y + 2 * iPerImageHeight));

m_myFlower[15].myFlower.SetPosXY((x + 6 * iPerImageWidth), (y + 3 * iPerImageHeight));

m_myFlower[16].myFlower.SetPosXY((x + 5 * iPerImageWidth), (y + 4 * iPerImageHeight));

m_myFlower[17].myFlower.SetPosXY((x + 4 * iPerImageWidth), (y + 5 * iPerImageHeight));

// 显示

for (i = 4; i

{

m_myFlower[i].bExist = TRUE;

Sleep(iElapseFast); // 停顿

}

// 3. 在心形图案的中心,显示一朵更大的花儿

m_myFlower[18].myFlower.Init(IDB_BITMAP1, ((x + 3 * iPerImageWidth) + iPerImageWidth / 2) - (iFirstFlowerWidth / 2) ,

((y + 3 * iPerImageHeight) + iPerImageHeight / 2) - (iFirstFlowerHeight / 2), iFirstNumFrame, iFirstNumFlowering);

m_myFlower[18].myFlower.SetWidthHeight(iFirstFlowerWidth, iFirstFlowerHeight);

m_myFlower[18].bExist = TRUE;

Sleep(iElapseSlow); // 停顿

// 4. 绘制蝴蝶飞舞

m_myButterfly.myButterfly.Init(IDB_BITMAP3, 0, 0, 37, 0);

m_myButterfly.myButterfly.SetWidthHeight(iWidth, iHeight);

m_myButterfly.bExist = TRUE;

Sleep(iElapseSlow); // 停顿

// 5. 在心形图案的下方显示祝福语和署名

// 祝福语

m_myBless.myButterfly.Init(IDB_BITMAP4, (x + 1 * iPerImageWidth), (y + 5 * iPerImageHeight), 1, 0);

m_myBless.myButterfly.SetWidthHeight((6 * iPerImageWidth), iPerImageHeight);

m_myBless.bExist = TRUE;

Sleep(iElapseSlow); // 停顿

// LOGO

m_myLogo.myButterfly.Init(IDB_BITMAP5, (x + 6 * iPerImageWidth), (y + 1 * iPerImageHeight), 1, 0);

//m_myLogo.myButterfly.SetWidthHeight();

m_myLogo.bExist = TRUE;

以上为部分源码,由于使用的是MFC编写的,生成代码过多,就不一一粘贴出来了.学习源于兴趣,其实从做这种小东西开始。慢慢的越学越有意思,如果阁下正处学习阶段,不妨参详,让学编程既有浪漫,又有丰富内容。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容