鱼C论坛

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

[学习笔记] 正弦曲线

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

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

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

x
本帖最后由 pwnmelife 于 2019-2-13 14:51 编辑
  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.         POINT apt[NUM];
  46.        
  47.         switch (message) {
  48.         case WM_CREATE:
  49.                 return 0;
  50.         case WM_PAINT:
  51.                 hdc = BeginPaint(hwnd, &ps);
  52.                 MoveToEx(hdc, 0, cyClient/2, NULL);
  53.                 LineTo(hdc, cxClient, cyClient / 2); //画一条直线
  54.                 for (i = 0; i < NUM; i++) {
  55.                         apt[i].x = i * cxClient / NUM;
  56.                         apt[i].y = (int)(cyClient / 2 * (1 - sin(TWOPI * i / NUM))); // (y/2 (1 - sin(2π(x/NUM))))
  57.                 }
  58.                 Polyline(hdc, apt, NUM);
  59.                 EndPaint(hwnd, &ps);
  60.                 return 0;
  61.         case WM_SIZE:
  62.                 cxClient = LOWORD(lParam);
  63.                 cyClient = HIWORD(lParam);
  64.                 return 0;
  65.         case WM_DESTROY:
  66.                 PostQuitMessage(0);
  67.                 return 0;
  68.         default:
  69.                 return DefWindowProc(hwnd, message, wParam, lParam);
  70.         }
  71. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 12:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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