/////////////////////画曲线函数////////////////////////////
////////////////////直角坐标下的////////////////////////
//y=fun(x)
//p---绘图设备指针
//fun---函数指针
//StartP1---x的起始值
//StartP2---x的终止值
//PX---坐标原点x方向位置
//PY---坐标原点y方向位置
//Mx---x方向放大倍数
//My---y方向放大倍数
/////////////////////////////////////////////////////////
void DrawCurve(HDC hDC,double (*fun)(double),double StartP1,double EndP1,int PX,int PY,double Mx,double My)
{
int i,N=int(Mx*(EndP1-StartP1));
double x,y,dx;
dx=(EndP1-StartP1)/N;
x=StartP1;
y=(*fun)(x);
MoveToEx(hDC,PX+int(x*Mx),PY-int(y*My),NULL);
for(i=1;i<=N;i++)
{
x=StartP1+i*dx;
y=(*fun)(x);
LineTo(hDC,PX+int(x*Mx),PY-int(y*My));
}
}
////////////////////直角坐标下的////////////////////////
//y=fun(x)
//p---绘图设备指针
//fun---函数指针
//StartP1---x的起始值
//StartP2---x的终止值
//PX---坐标原点x方向位置
//PY---坐标原点y方向位置
//Mx---x方向放大倍数
//My---y方向放大倍数
/////////////////////////////////////////////////////////
void DrawCurve(HDC hDC,double (*fun)(double),double StartP1,double EndP1,int PX,int PY,double Mx,double My)
{
int i,N=int(Mx*(EndP1-StartP1));
double x,y,dx;
dx=(EndP1-StartP1)/N;
x=StartP1;
y=(*fun)(x);
MoveToEx(hDC,PX+int(x*Mx),PY-int(y*My),NULL);
for(i=1;i<=N;i++)
{
x=StartP1+i*dx;
y=(*fun)(x);
LineTo(hDC,PX+int(x*Mx),PY-int(y*My));
}
}
解决方案 »
- edit有replacesel但combo box没有,很不爽
- 如何获取iwebbrowser2控件的链接点击事件 sdk
- CTime问题
- 我自已做一个Edit框,如何才能切换输入法?
- 用CAsyncSocket写的客户端程序是否可与UNIXserver通讯?
- 怎样在CView里访问CChildFrame里的成员变量
- 如何判断我点击了窗口标题栏上的问号按钮?以及如何接受这个事件
- 如何在sdk中实现ole拖放
- INSERT INTO table_name(column1,column2,...) VALUES (value1,value2, ...) 问题,请大家帮帮忙!
- 有没有把jdk的编译信息输出到文本文件中
- 怎么才能把一个对话框上的一个static控件和一个类的对象相联系,并且该对象为该对话框的一个成员变量???
- MFC问题
//定义曲线颜色,红色
CPen newpen1;
CPen *poldpen1;
newpen1.CreatePen(PS_SOLID,1,RGB(255,0,0));
poldpen1=m_dcMem.SelectObject(&newpen1); m_dcMem.MoveTo(rectStaticClient.left-60,rectStaticClient.bottom-240); for(int b=0;b<25200;b++)
{ double x=b+rectStaticClient.left-60;
double y=sin(x/20);
CPoint pt(x,y*30+rectStaticClient.bottom-240);
if(b==0)
m_dcMem.MoveTo(pt);
else
m_dcMem.LineTo(pt); } 显示不出,不知道哪里错了
调用下面代码,正弦曲线就出来了
DrawCurve(m_dcMem.m_hDC,sin,0,6.28,300,300,30,30);
{
CPaintDC dc(this); CPen newpen;
CPen* poldpen;
newpen.CreatePen(PS_SOLID,1,RGB(179,255,255));
poldpen=m_dcMem.SelectObject(&newpen);//绘制坐标轴 int M=40;
//横轴
m_dcMem.MoveTo(rectStaticClient.left-60,rectStaticClient.bottom-100-M);
m_dcMem.LineTo(25200,rectStaticClient.bottom-100-M); m_dcMem.LineTo(25200-40,rectStaticClient.bottom-103-M);
m_dcMem.LineTo(25200,rectStaticClient.bottom-100-M);
m_dcMem.LineTo(25200-40,rectStaticClient.bottom-97-M);
//横轴刻度 int k=100000;
for(int x=0;x<k+1;x++)
{
if(x%25==0)
{
m_dcMem.MoveTo((int)(rectStaticClient.left+x-60),
(int)(rectStaticClient.bottom-100-M));
m_dcMem.LineTo((int)(rectStaticClient.left+x-60),
(int)(rectStaticClient.bottom-105-M)); }
if(x%125==0)
{
m_dcMem.MoveTo((int)(rectStaticClient.left+x-60),
(int)(rectStaticClient.bottom-100-M));
m_dcMem.LineTo((int)(rectStaticClient.left+x-60),
(int)(rectStaticClient.bottom-110-M)); XPos.Format("%d",4*x);
Xsize=dc.GetTextExtent(XPos,XPos.GetLength()); m_dcMem.SetTextColor(RGB (0, 255, 255));
m_dcMem.SetBkColor(RGB (0,0,0)); m_dcMem.TextOut((int)(rectStaticClient.left+x-60-Xsize.cx/2),
rectStaticClient.bottom-85-M,XPos);
}
}
m_dcMem.MoveTo(rectStaticClient.left-60,rectStaticClient.bottom-100-M);
m_dcMem.LineTo(rectStaticClient.left-60,rectStaticClient.bottom-400-M);
m_dcMem.LineTo(rectStaticClient.left-62,rectStaticClient.bottom-390-M);
m_dcMem.LineTo(rectStaticClient.left-60,rectStaticClient.bottom-400-M);
m_dcMem.LineTo(rectStaticClient.left-58,rectStaticClient.bottom-390-M);
int l=1000;
for(int y=0;y<l+1;y++)
{
if(y%100==0)
{
m_dcMem.MoveTo((int)(rectStaticClient.left-60),
(int)(rectStaticClient.bottom-100-M-280*y/1000));
m_dcMem.LineTo((int)(rectStaticClient.left-54),
(int)(rectStaticClient.bottom-100-M-280*y/1000));
}
} for(y=0;y<l+1;y++)
{
if(y%20==0)
{
m_dcMem.MoveTo((int)(rectStaticClient.left-60),
(int)(rectStaticClient.bottom-100-M-280*y/1000));
m_dcMem.LineTo((int)(rectStaticClient.left-57),
(int)(rectStaticClient.bottom-100-M-280*y/1000));
}
}////以下绘制扭矩曲线
//定义曲线颜色,红色
CPen newpen1;
CPen *poldpen1;
newpen1.CreatePen(PS_SOLID,1,RGB(255,0,0));
poldpen1=m_dcMem.SelectObject(&newpen1); m_dcMem.MoveTo(rectStaticClient.left-60,rectStaticClient.bottom-240); for(int b=0;b<25200;b++)
{ double x=b+rectStaticClient.left-60;
double y=sin(x/20);
CPoint pt(x,y*30+rectStaticClient.bottom-240);
if(b==0)
m_dcMem.MoveTo(pt);
else
m_dcMem.LineTo(pt); }
m_dcMem.SelectObject(poldpen1);///以下为通过函数BitBlt()来显示上面画的全部内容:黑色背景,坐标,刻度,曲线 dc.BitBlt(offsetx,offsety+10,m_size.cx,m_size.cy-20,
&m_dcMem, sourcex, sourcey,SRCCOPY);}全部在这了,不知道哪出了问题,谢谢了