鱼C论坛

 找回密码
 立即注册
查看: 1636|回复: 0

[学习笔记] 贝塞尔曲线

[复制链接]
发表于 2019-2-13 15:11:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <Windows.h>
  2. #include <strsafe.h>
  3. #include "SysMets.h"
  4. #include <math.h>

  5. #define NUM 1000
  6. #define TWOPI (2 * 3.14159)
  7. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


  8. int WINAPI WinMain(HINSTANCE hInstance,
  9.         HINSTANCE hPrevInstance,
  10.         LPSTR lpCmdLine,
  11.         int nShowCmd) {
  12.         static TCHAR szAppName[] = TEXT("Bill");
  13.         HWND hwnd;
  14.         WNDCLASS wndclass;
  15.         MSG msg;
  16.        
  17.         wndclass.cbClsExtra = 0;
  18.         wndclass.cbWndExtra = 0;

  19.         wndclass.hInstance = hInstance;
  20.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  21.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  22.         wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  23.         wndclass.lpszClassName = szAppName;
  24.         wndclass.lpszMenuName = NULL;
  25.         wndclass.lpfnWndProc = WndProc;
  26.         wndclass.style = CS_HREDRAW | CS_VREDRAW;

  27.         RegisterClass(&wndclass);
  28.         hwnd = CreateWindow(TEXT("Bill"), TEXT("Tip"), WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  29.                 CW_USEDEFAULT, 40, CW_USEDEFAULT, 100,
  30.                 NULL, NULL, hInstance, NULL);

  31.         ShowWindow(hwnd, nShowCmd);
  32.         UpdateWindow(hwnd);
  33.         while (GetMessage(&msg, NULL, 0, 0)) {
  34.                 TranslateMessage(&msg);
  35.                 DispatchMessage(&msg);
  36.         }
  37.         return 0;

  38. }

  39. LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
  40.         WPARAM wParam, LPARAM lParam) {
  41.         HDC hdc;
  42.         static int cxClient, cyClient;
  43.         int i;
  44.         PAINTSTRUCT ps;
  45.         static POINT apt[4];
  46.        
  47.         switch (message) {
  48.         case WM_CREATE:
  49.                 return 0;
  50.         case WM_PAINT:
  51.                 hdc = BeginPaint(hwnd, &ps);
  52.                 PolyBezier(hdc, apt, 4);
  53.                 EndPaint(hwnd, &ps);
  54.                 return 0;
  55.         case WM_LBUTTONDOWN:
  56.                 hdc = GetDC(hwnd);
  57.                 SelectObject(hdc, GetStockObject(WHITE_PEN));
  58.                 PolyBezier(hdc, apt, 4);
  59.                 apt[1].x = LOWORD(lParam);
  60.                 apt[1].y = HIWORD(lParam);
  61.                 SelectObject(hdc, GetStockObject(BLACK_PEN));
  62.                 PolyBezier(hdc, apt, 4);
  63.                 ReleaseDC(hwnd, hdc);
  64.                 return 0;
  65.         case WM_RBUTTONDOWN:
  66.                 hdc = GetDC(hwnd);
  67.                 SelectObject(hdc, GetStockObject(WHITE_PEN));
  68.                 PolyBezier(hdc, apt, 4);
  69.                 apt[2].x = LOWORD(lParam);
  70.                 apt[2].y = HIWORD(lParam);
  71.                 SelectObject(hdc, GetStockObject(BLACK_PEN));
  72.                 PolyBezier(hdc, apt, 4);
  73.                 ReleaseDC(hwnd, hdc);
  74.                 return 0;

  75.         case WM_SIZE:
  76.                 cxClient = LOWORD(lParam);
  77.                 cyClient = HIWORD(lParam);
  78.                 apt[0].x = cxClient / 4;
  79.                 apt[0].y = cyClient / 2;

  80.                 apt[1].x = cxClient / 2;
  81.                 apt[1].y = cyClient / 4;

  82.                 apt[2].x = cxClient / 2;
  83.                 apt[2].y = cyClient * 3 / 4;

  84.                 apt[3].x = cxClient * 3 / 4;
  85.                 apt[3].y = cyClient / 2;
  86.                 return 0;
  87.         case WM_DESTROY:
  88.                 PostQuitMessage(0);
  89.                 return 0;
  90.         default:
  91.                 return DefWindowProc(hwnd, message, wParam, lParam);
  92.         }
  93. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 21:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表