您好,登錄后才能下訂單哦!
本篇內容介紹了“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語言怎么繪制圣誕水晶球”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。