我在画y=sin()函数图像,如何将座标设置在clentRect的中央啊?

解决方案 »

  1.   

    CRect rect;
    GetClientRect(&rect);
    dc.SetMapMode(MM_ANISOTROPIC); //设置不同比例的坐标系
    dc.SetViewportOrg(rect.left,rect.bottom); //坐标原点 右下脚
    dc.SetViewportExt(rect.right,rect.bottom); //视窗浣范围
    dc.SetWindowOrg(0,0);
    dc.SetWindowExt(rect.right,-rect.bottom);
      

  2.   

    dc.SetViewportOrg(rect.left,rect.bottom);
    --->
    dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);
      

  3.   

    还不行啊!我的代码如下:
    CClientDC dc(this); // device context for painting
    CRect rect;
    double y;
    int x;
    GetClientRect(&rect);
    dc.MoveTo(0,rect.Height() / 2);
    dc.LineTo (rect.Width(),rect.Height() / 2); dc.MoveTo(rect.Width()/2,0);
    dc.LineTo (rect.Width()/2,rect.Height()); dc.SetTextColor(RGB(0,0,255)); ClientToScreen(&rect); for (x=1;x<rect.Width()-10;)
    {
    y=sin(x);
    dc.TextOut (x,y+rect.Height() / 2,"*");
    x=x+10;
             』
      

  4.   

    CRect rect;
    GetClientRect(&rect);
    dc.SetMapMode(MM_ANISOTROPIC);//设置不同比例的坐标系
    dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);//坐标原点 
    dc.SetViewportExt(rect.right,rect.bottom);//视窗浣范围
    dc.SetWindowOrg(0,0);
    dc.SetWindowExt(rect.right,-rect.bottom);dc.MoveTo(0,0);
    dc.LineTo(100,100);//看看效果
      

  5.   

    //接上上楼
    CClientDC dc(this); // device context for painting
    CRect rect;
    GetClientRect(&rect);
    dc.SetMapMode(MM_ANISOTROPIC);//设置不同比例的坐标系
    dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);//坐标原点 
    dc.SetViewportExt(rect.right,rect.bottom);//视窗浣范围
    dc.SetWindowOrg(0,0);
    dc.SetWindowExt(rect.right,-rect.bottom);dc.MoveTo(-rect.right / 2,0);
    dc.LineTo(rect.right / 2,0);
    dc.MoveTo(0,-rect.bottom / 2);
    dc.LineTo(0,rect.bottom / 2);double pi = 3.1415;
    double rate = rect.Width() / (2 * pi);
    for(double i = - pi; i < pi; i += 0.1)
    {
    if(i == -pi)
    dc.MoveTo(i * rate,sin(i) * rate);
    else
    dc.LineTo(i * rate,sin(i) * rate);
    }