C语言怎么绘制圣诞水晶球
短信预约 -IT技能 免费直播动态提醒
本篇内容介绍了“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); //创建一个窗口hwndHRGN Ellip = CreateEllipticRgn(10, 32, 100+10, 100+32);//设置一个逻辑的图形rectSetWindowRgn(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); elsemciSendString("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语言怎么绘制圣诞水晶球”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341