3,881
社区成员




HDC PaintSin(HDC hdc,HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
RECT rect;
int i=0;
POINT pt[NUM];
TCHAR buffer[30];
GetClientRect(hwnd,&rect);
SetViewportOrgEx(hdc,rect.right/2,rect.bottom/2,NULL);
SetTextColor(hdc,RGB(0,255,0));
TextOut(hdc,5,-15,buffer,wsprintf(buffer,TEXT("f(x)=sin(x),(%d,%d)"),rect.right/2,rect.bottom/2));
SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(0,255,0)));
for(i=0;i<NUM;++i)
{
pt[i].y=(int)sin(i*PI/NUM);
pt[i].x=i*rect.right/NUM;
//pt[i].y=(int)(rect.bottom/2*(1-sin(PI*i/100)));
}
Polyline(hdc,pt,NUM);
SetViewportOrgEx(hdc,0,0,NULL);
SetTextColor(hdc,RGB(0,0,0));
DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
return hdc;
}
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
WL_SaveDC=PaintSin(hdc,hwnd,message,wparam,lparam);
SaveDC(hdc);
PaintLine(hdc,hwnd,message,wparam,lparam);
RestoreDC(hdc,-1);
EndPaint(hwnd,&ps);
return 0;
TextOut(hdc,5,-15,buffer,wsprintf(buffer,TEXT("f(x)=sin(x),(%d,%d)"),rect.right/2,rect.bottom/2));
这句代码,把字符显示到 第一象限了,也就是(+x,+y).