博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows编程——万花筒绘制
阅读量:6309 次
发布时间:2019-06-22

本文共 3024 字,大约阅读时间需要 10 分钟。

#include
#include
#include
#include
#define Pi 3.1415926long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam);BOOL InitWindowsClass(HINSTANCE hInstance);BOOL InitWindows(HINSTANCE hInstance, int nCmdShow);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ MSG Message; if (!InitWindowsClass(hInstance)) return FALSE; if (!InitWindows(hInstance, nCmdShow)) return FALSE; while (GetMessage(&Message, 0, 0, 0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam;}long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam){ HDC hDC; HPEN hPen; PAINTSTRUCT PtStr; int n = 25; POINT points[25]; double angel = 2 * Pi / n; for (int i = 0; i < n; i++) { points[i].x = static_cast
(320 + 180 * cos(i*angel)); points[i].y = static_cast
(250 + 180 * sin(i*angel)); } switch (iMessage) { case WM_PAINT: hDC = BeginPaint(hWnd, &PtStr); for (int i = 0; i < 25; i++) { hPen = (HPEN)GetStockObject(NULL_PEN); SelectObject(hDC, hPen); LineTo(hDC, points[i].x, points[i].y); DeleteObject(hPen); if (i == 0) { for (int j = 1; j < n; j++) { switch (j % 6) { case 1: case 2: hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); break; case 3: case 4: hPen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); break; case 5: case 0: hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); break; } SelectObject(hDC, hPen); LineTo(hDC, points[j].x, points[j].y); MoveToEx(hDC, points[i].x, points[i].y, NULL); DeleteObject(hPen); } } else { for (int j = i + 1; j < n; j++) { switch (j % 6) { case 1: case 2: hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); break; case 3: case 4: hPen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); break; case 5: case 0: hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); break; } SelectObject(hDC, hPen); LineTo(hDC, points[j].x, points[j].y); MoveToEx(hDC, points[i].x, points[i].y, NULL); DeleteObject(hPen); Sleep(50); } } } EndPaint(hWnd, &PtStr); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return(DefWindowProc(hWnd, iMessage, wParam, lParam)); }}BOOL InitWindows(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hWnd = CreateWindow("WinFill", " 万花筒", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}BOOL InitWindowsClass(HINSTANCE hInstance) { WNDCLASS WndClass; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH)); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hIcon = LoadIcon(NULL, "END"); WndClass.hInstance = hInstance; WndClass.lpfnWndProc = WndProc; WndClass.lpszClassName = "WinFill"; WndClass.lpszMenuName = NULL; WndClass.style = CS_HREDRAW | CS_VREDRAW; return RegisterClass(&WndClass);}
绘制万花筒时的截图:
 
 
尝试了多次后,终于可以让图片在博客里显示了...... 
 

转载于:https://www.cnblogs.com/Genesis2018/p/8304769.html

你可能感兴趣的文章
因为你是前端程序员!
查看>>
数据库设计中的14个技巧
查看>>
Android学习系列(5)--App布局初探之简单模型
查看>>
git回退到某个历史版本
查看>>
ecshop
查看>>
HTML5基础(二)
查看>>
在GCE上安装Apache、tomcat等
查看>>
在Mac 系统下进行文件的显示和隐藏
查看>>
ue4(c++) 按钮中的文字居中的问题
查看>>
技能点
查看>>
读书笔记《乌合之众》
查看>>
Hadoop日记Day1---Hadoop介绍
查看>>
iOS 学习资料汇总
查看>>
centos7 yum安装jdk
查看>>
Bluedroid与BluZ,蓝牙测试方法的变动(基于bludroid和BlueZ的对比)
查看>>
接口和抽象类有什么区别
查看>>
Linux 下添加用户,修改权限
查看>>
请问view controller scene,该如何删除
查看>>
bootstrap新闻模块样式模板
查看>>
zzzzw_在线考试系统①准备篇
查看>>