c/c++语言开发共享C语言百行代码绘制圣诞水晶球

目录序项目代码总结序我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。嗨!这里是狐狸~~今天就是圣诞节了,再过一个星期就是2022年了,最近总是感觉伤感,有些事情就是比想象中来的快一

目录
  • 项目代码
  • 总结

我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。

嗨!这里是狐狸~~

今天就是圣诞节了,再过一个星期就是2022年了,最近总是感觉伤感,有些事情就是比想象中来的快一些,希望大家都可以把握2021年最后的时间,不留遗憾吧,后天圣诞节,今天再教大家一个圣诞项目吧,圣诞水晶球,今天这个呢代码不多,但难度会有点,因为这个涉及桌面,就是可以在桌面实现,希望大家可以认真看,认真学吧。

同样,先给大家看效果吧

C语言百行代码绘制圣诞水晶球

效果还是很不错的,再加上一个音乐,女朋友看完就马上同意你了,嘿嘿,这里就不再是简单的窗口了,难度有一些,但也不大,毕竟代码也不多,好了,认真学,认真的尝试哦!

项目代码

这是我第一次只用一个代码段,因为代码确实不多,我觉得分段就没必要了,而且其中必要的地方,我也加了详细的注释,应该还好,难就难在之前没有用windows库,这次用了,效果看起来就会舒服很多,怎么样,学会了赶快拿给心中的那个人看吧!

  #include <stdio.h>  #include <windows.h>  #include <graphics.h>  #include <commctrl.h>  #include <mmsystem.h>  #pragma comment(lib,"winmm.lib")     int main()  {  	keybd_event(vk_lwin, 0, 0, 0);  	keybd_event('d', 0, 0, 0);  	keybd_event('d', 0, 2, 0);  	keybd_event(vk_lwin, 0, 2, 0);  	  	sleep(3000);  	int cx = getsystemmetrics(sm_cxscreen);  	int cy = getsystemmetrics(sm_cyscreen);     	hwnd hwnd = initgraph(500,500); //创建一个窗口hwnd  	hrgn ellip = createellipticrgn(10, 32, 100+10, 100+32);//设置一个逻辑的图形rect  	setwindowrgn(hwnd, ellip, true);  //设置窗口的区域  	setforegroundwindow(hwnd);  	movewindow(hwnd, cx / 2 - 120, cy / 2, 500, 500, true);     	mcisendstring("open res/music.mp3", 0, 0, 0);    //打开  	mcisendstring("play res/music.mp3 repeat", 0, 0, 0);    //播放  	bool isplay = true;  //音乐是否正在播放     	int sence = 3;  //场景  	int frame = 0;  //帧数  	image img[30];  	int maxframe[] = { 20, 7, 4, 15, 10}; //每一种场景的图片的张数  	char picpath[30] = { 0 };  //字符串 图片的路径  	for (int i = 0; i < maxframe[sence]; i++)  	{  		sprintf(picpath, "res/%02d-%02d.bmp", sence, i);  		loadimage(&img[i], picpath, 100, 100);  	}     	/*---------------------------------------------------------*/  	//获取到桌面图标的窗口  	hwnd zmwnd = findwindow("progman","program manager");  //桌面窗口  	hwnd bzwnd = findwindowex(zmwnd, 0, "shelldll_defview", null);  //壁纸窗口  	hwnd tbwnd = findwindowex(bzwnd, 0, "syslistview32", "folderview");  //图标窗口     	hwnd workhwnd = null;  	while (tbwnd == null)//必须存在桌面窗口层次  	{  		workhwnd = findwindowexa(0, workhwnd, "workerw", null);//获得workerw类的窗口  		if (workhwnd == null)  			break;//未知错误  		bzwnd = findwindowexa(workhwnd, null, "shelldll_defview", null);  		if (bzwnd == null)  			continue;  		tbwnd = findwindowexa(bzwnd, null, "syslistview32", null);  	}     	dword dwstyle = (dword)getwindowlong(tbwnd, gwl_style);  	if (dwstyle & lvs_autoarrange)  		setwindowlong(tbwnd, gwl_style, dwstyle & ~lvs_autoarrange);     	dword dwexstyle = (dword)listview_getextendedlistviewstyle(tbwnd, gwl_exstyle);  	if (dwexstyle & lvs_ex_snaptogrid)  		listview_setextendedlistviewstyle(tbwnd, dwexstyle & ~lvs_ex_snaptogrid);        	//指挥它 威胁它 图标的窗口  	int count = sendmessage(tbwnd, lvm_getitemcount, 0, 0);  	for (int i = 0; i < count; i++)  		sendmessage(tbwnd, lvm_setitemposition, i, (3000 << 16) + 100);  	point dir[14] = { { 868 * cx / 1920, 316 * cy / 1080 }, { 730 * cx / 1920, 207 * cy / 1080 },   	{ 591 * cx / 1920, 221 * cy / 1080 }, { 515 * cx / 1920, 327 * cy / 1080 }, { 542 * cx / 1920, 469 * cy / 1080 },  	{ 610 * cx / 1920, 624 * cy / 1080 }, { 723 * cx / 1920, 746 * cy / 1080 }, { 870 * cx / 1920, 814 * cy / 1080 },   	{ 1012 * cx / 1920, 744 * cy / 1080 }, { 1130 * cx / 1920, 626 * cy / 1080 },  	{ 1219 * cx / 1920, 485 * cy / 1080 }, { 1225 * cx / 1920, 328 * cy / 1080 }, { 1156 * cx / 1920, 225 * cy / 1080 },  	{ 1012 * cx / 1920, 217 * cy / 1080 } };     	exmessage m;                         //定义消息  	int oldsence;  	while (1){     		if (peekmessage(&m, em_mouse))   //如果获取到一条鼠标消息  		{  			switch (m.message)  			{  			case wm_lbuttondown:  //点下左键  换一个场景  				oldsence = sence;  				do  				{  					sence = rand() % (sizeof(maxframe) / sizeof(maxframe[0])); //0-5  				} while (sence == oldsence);     				for (int i = 0; i < maxframe[sence]; i++)  				{  					sprintf(picpath, "res/%02d-%02d.bmp", sence, i);  					loadimage(&img[i], picpath, 100, 100);  				}  				sendmessage(hwnd, wm_syscommand, 0xf012, 0);  			  				break;  			case wm_rbuttondown:   				if (isplay)  //正在播放  					mcisendstring("pause res/music.mp3", 0, 0, 0);    				else  					mcisendstring("play res/music.mp3 repeat", 0, 0, 0);  				  				isplay = !isplay; //取反  				break;  			}  		}  		else  //绘制界面  		{  			putimage(0, 0, &img[frame++]);  			if (frame > maxframe[sence] - 1)frame = 0;     			for (int i = 0; i < 14; i++)  			{  				sendmessage(tbwnd, lvm_setitemposition, i, (dir[i].y << 16) + dir[i].x);  			}     			int x = dir[0].x;  			int y = dir[0].y;  			for (int i = 0; i < 13; i++)  			{  				dir[i].x = dir[i + 1].x;  				dir[i].y = dir[i + 1].y;  			}  			dir[13].x = x;  			dir[13].y = y;  		}  	}  	return 0;  }   

总结

代码真的非常的少,认真理解每一行的作用,相信你们很快就可以理解了。圣诞节快到了,程序员的快乐无非就是可以代码写出一些特别的东西了,主要是确实好用,哈哈哈,不管男女,好啦,希望大家可以在圣诞节的那天都会有好运气,提前祝大家圣诞节快乐啦!

视频讲解

这次也有视频讲解,代码不多,看视频会理解的更快! 

到此这篇关于c语言百行代码绘制圣诞水晶球的文章就介绍到这了,更多相关c语言绘制圣诞水晶球内容请搜索<计算机技术网(www.ctvol.com)!!>以前的文章或继续浏览下面的相关文章希望大家以后多多支持<计算机技术网(www.ctvol.com)!!>!

需要了解更多c/c++开发分享C语言百行代码绘制圣诞水晶球,都可以关注C/C++技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/990662.html

(0)
上一篇 2021年12月25日
下一篇 2021年12月25日

精彩推荐