如何从文件WinAPI制作绘图



我们有txt文件数量:

60 0

4120

180年20

-28

180年28日

-28

30 28

-28

60 0

我需要一个情节与第一列在水平坐标线和第二列在垂直坐标线就像这张照片。但是现在我有一个这样的

std::ifstream omega_file("test.txt");
MoveToEx(hdc, 0, 0, NULL); // start point
double T_new = 0;
while (!omega_file.eof())
{
omega_file >> T >> Omega;
T_new = T_new + T;
LineTo(hdc, T_new / 60 * horizontal_step_grid, - Omega * vertical_step_grid);
MoveToEx(hdc, T_new / 60 * horizontal_step_grid, - Omega * vertical_step_grid, NULL);
}

您需要绘制两条线(水平线,然后垂直线),而不是每一个坐标绘制一条线。

还要注意,LineTo()设置当前位置,因此MoveToEx()到相同坐标是冗余的。

试试这个:

std::ifstream omega_file("test.txt");
MoveToEx(hdc, 0, 0, NULL); // start point
int currentY = 0;
double T_new = 0;
while (omega_file >> T >> Omega)
{
T_new = T_new + T;
int x = T_new / 60 * horizontal_step_grid;
int nextY = - Omega * vertical_step_grid;
LineTo(hdc, x, currentY);
LineTo(hdc, x, nextY);
currentY = nextY;
}

最新更新