在vc中如何用c语言编程绘制坐标系并根据外来输入绘制波形?

我不知道怎么在vc中用c语言绘制坐标系,并根据外来输入在坐标系中绘制波形



#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    // 创建窗口
    HWND hwnd;
    WNDCLASS wc = { 0 };
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszClassName = "MyClass";
    RegisterClass(&wc);
    hwnd = CreateWindow("MyClass", "Waveform", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // 消息循环
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);

        // 绘制坐标系
        MoveToEx(hdc, 50, 50, NULL);
        LineTo(hdc, 50, 550);
        LineTo(hdc, 750, 550);

        // 外来输入数据(示例)
        int waveform[] = { 100, 200, 300, 400, 500, 400, 300, 200, 100 };

        // 绘制波形
        int x = 50;
        int y = 550 - waveform[0];
        MoveToEx(hdc, x, y, NULL);
        for (int i = 1; i < sizeof(waveform) / sizeof(waveform[0]); i++)
        {
            x += 700 / (sizeof(waveform) / sizeof(waveform[0]) - 1);
            y = 550 - waveform[i];
            LineTo(hdc, x, y);
        }

        EndPaint(hwnd, &ps);
        break;
    }
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

希望得到采纳