坐标计算程序

coordinate calculation program

我想为windows做一个简单的坐标计算程序: application

可以通过鼠标左键移动X_Line(红色)和Y_Line(蓝色)并显示坐标。

但是我需要帮助来为这个场景制作坐标部分和函数。

请帮助我完成程序的任何部分!?!

感谢您的帮助,

处理WM_LBUTTONDOWN并记录鼠标位置,然后发送绘画消息在该坐标处绘画。

#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    static int xcoord = -1;
    static int ycoord = -1;
    switch(msg)
    {
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);

        if(xcoord >= 0 && ycoord >= 0)
        {
            RECT rc;
            GetClientRect(hWnd, &rc);

            //draw horizontal line
            MoveToEx(hdc, 0, ycoord, NULL);
            LineTo(hdc, rc.right, ycoord);

            //draw vertical line
            MoveToEx(hdc, xcoord, 0, NULL);
            LineTo(hdc, xcoord, rc.bottom);
        }

        EndPaint(hWnd, &ps);
        return 0;
    }

    case WM_LBUTTONDOWN:
    {
        xcoord = ((int)(short)LOWORD(lparam));
        ycoord = ((int)(short)HIWORD(lparam));
        InvalidateRect(hWnd, NULL, TRUE);
        return 0;
    }

    case WM_DESTROY:

        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hWnd, msg, wparam, lparam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
    wcex.lpfnWndProc = WndProc;
    wcex.hInstance = hInstance;
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wcex.lpszClassName = TEXT("classname");
    RegisterClassEx(&wcex);

    CreateWindow(wcex.lpszClassName, NULL, WS_VISIBLE | WS_OVERLAPPEDWINDOW,
        0, 0, 600, 400, 0, 0, hInstance, 0);

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}