This article describes the C + + drawing sine line of the implementation code, shared for everyone to reference.
The main functional code is as follows:
Copy Code code as follows:
Case WM_PAINT:
HDC = BeginPaint (hWnd, &ps);
TODO: Add any drawing code here ...
Draw the positive and the black line
#define PI 3.1415926
#define SEGMENT 500
int cxclient,cyclient;
RECT RECT;
:: GetClientRect (HWnd, &rect);
Cxclient = Rect.right-rect.left;
Cyclient = Rect.bottom-rect.top;
Point Pt[segment];
for (int i=0;i<segment;i++)
{
pt[i].x = i * cxclient/segment; The length of the cxclient is divided into segment.
PT[I].Y = (int) (CYCLIENT/2) * (1-sin (2 * PI * i/segment)); Because the sin (2pi) is reversed, because the mathematical coordinate y-axis is up and the coordinate y-axis in the system is downward, the +CYCLIENT/2 is to move the coordinate origin to the upper-left corner
}
::P olyline (HDC, PT, SEGMENT); Drawing functions
EndPaint (HWnd, &ps);
Break
I hope this article will help you with the C + + program design.