📄 paintbak.cpp
字号:
return 0;
}
if(error!=0)
return 0;
//-------------------------------------------把所得的CString类型的partsumcs复制给char类型的数组partsumch
strncpy(partsumch,(LPCTSTR)partsumcs,18);
//-----------------------------
/////////////////////////////////-----------------关键!重新构造expres数组
for(k=0;k<M;part[k]='\0',k++); //part数组重新清\0
BYTE rb1,rb2;
rb1=partsumch[0]=='1'&&partsumch[1]=='.'&&partsumch[2]=='#';
rb2=partsumch[1]=='1'&&partsumch[2]=='.'&&partsumch[3]=='#';
if(rb1||rb2||fabs(atof(partsumcs))>=1e14)
{
outrange=1;
return 0;
}
for(rb1=j-length,k=0;partsumch[k]!='\0';rb1++,k++)//构造新的expres数组的前半部分
expres[rb1]=partsumch[k];
for(rb2=i+1;expresbak[rb2]!='\0';rb1++,rb2++)//构造新的expres数组的后半部分
expres[rb1]=expresbak[rb2];
expres[rb1]=0;
strcpy(expresbak,expres);
i=j-length+k-1;//调整i的位置,使之指向新的expres和旧的expres的接壤部分
break;
}
}
}
}
if(fabs(result=powerchge(expres,xl,flag))>100)//对结果过大的处理
outrange=1;
return result;
}
/////////////////////////////////////////////////////////////////////////////
// CPaint message handlers
void CPaint::OnPaint()
{
CPaintDC dc(this); // device context for painting
CWnd* pWnd=GetDlgItem(IDC_COLOR); //获得静态文本控件的指针
pWnd->UpdateWindow();
CDC* pDC=pWnd->GetDC(); //获得文本控件相关的设备描述?
CBrush drawBrush; //--------------
drawBrush.CreateSolidBrush(color);
pDC->SelectObject(drawBrush);
CRect rcClient;
pWnd->GetClientRect(rcClient);
pDC->Rectangle(rcClient); //填充静态文本控件的颜色
ReleaseDC(pDC);
//-----------------------------
CWnd* pEdit; //获得EDIT控件的指针
if(flag==1)
pEdit=GetDlgItem(IDC_EXPRES);
else
if(flag==2)
pEdit=GetDlgItem(IDC_X_EXPRES);
else
if(flag==3)
pEdit=GetDlgItem(IDC_Y_EXPRES);
else
if(flag==4)
pEdit=GetDlgItem(IDC_EXPRES2);
pDC=pEdit->GetDC();
char expres[M];
if(flag==1)
strncpy(expres,(LPCTSTR)this->m_expres,sizeof(expres)); //把CString变量COPY到expres[]里
else
if(flag==2)
strncpy(expres,(LPCTSTR)this->m_xexpres,sizeof(expres));
else
if(flag==3)
strncpy(expres,(LPCTSTR)this->m_yexpres,sizeof(expres)); //把CString变量COPY到expres[]里
else
if(flag==4)
strncpy(expres,(LPCTSTR)this->m_pexpres,sizeof(expres)); //把CString变量COPY到expres[]里
char *serch=expres;
pDC->SelectStockObject(DEFAULT_GUI_FONT); //选择与对话框默认字体一样的字体画字
pDC->SetTextColor(texnew);
for(BYTE i=0;*serch!='\0';serch++,i++) //-------------------------
{
if(flag==1&&*serch=='x')
{
pDC->SetTextColor(RGB(255,128,0));
pDC->TextOut(6*i+1,1,"x");
pDC->SetTextColor(texnew);
}
else
if((flag==2||flag==3)&&*serch=='t')
{
pDC->SetTextColor(RGB(255,128,0));
pDC->TextOut(6*i+1,1,"t");
pDC->SetTextColor(texnew);
}
else
if(flag==4&&*serch=='r')
{
pDC->SetTextColor(RGB(255,128,0));
pDC->TextOut(6*i+1,1,"r");
pDC->SetTextColor(texnew);
}
else
if (*serch=='e')
{
pDC->SetTextColor(RGB(255,128,0));
pDC->TextOut(6*i+1,1,"e");
pDC->SetTextColor(texnew);
}
else
if (*serch=='p')
{
pDC->SetTextColor(RGB(255,128,0));
pDC->TextOut(6*i+1,1,"p");
pDC->SetTextColor(texnew);
}
else
if (*serch=='+')
{
pDC->TextOut(6*i+1,1,"+");
}
else
if (*serch=='-')
{
pDC->TextOut(6*i+1,1,"-");
}
else
if (*serch=='*')
{
pDC->TextOut(6*i+1,1,"*");
}
else
if (*serch=='/')
{
pDC->TextOut(6*i+1,1,"/");
}
else
if (*serch=='(')
{
pDC->TextOut(6*i+1,1,"(");
}
else
if (*serch=='^')
{
pDC->TextOut(6*i+1,1,"^");
}
else
if (*serch==')')
{
pDC->TextOut(6*i+1,1,")");
}
if (*serch=='^')
{
pDC->TextOut(6*i+1,1,"^");
}
else
if (*serch=='l'&&*(serch+1)=='n')
{
pDC->TextOut(6*i+1,1,"ln");
}
else
if (*serch=='s'&&*(serch+1)=='i'&&*(serch+2)=='n'&&*(serch+3)!='h')
{
pDC->TextOut(6*i+1,1,"sin");
}
else
if (*serch=='c'&&*(serch+1)=='o'&&*(serch+2)=='s'&&*(serch+3)!='h')
{
pDC->TextOut(6*i+1,1,"cos");
}
else
if (*serch=='t'&&*(serch+1)=='a'&&*(serch+2)=='n'&&*(serch+3)!='h')
{
pDC->TextOut(6*i+1,1,"tan");
}
else
if (*serch=='c'&&*(serch+1)=='t'&&*(serch+2)=='g')
{
pDC->TextOut(6*i+1,1,"ctg");
}
else
if (*serch=='f'&&*(serch+1)=='a'&&*(serch+2)=='b'&&*(serch+3)=='s')
{
pDC->TextOut(6*i+1,1,"fabs");
}
else
if (*serch=='a'&&*(serch+1)=='s'&&*(serch+2)=='i'&&*(serch+3)=='n')
{
pDC->TextOut(6*i+1,1,"asin");
}
else
if (*serch=='a'&&*(serch+1)=='c'&&*(serch+2)=='o'&&*(serch+3)=='s')
{
pDC->TextOut(6*i+1,1,"acos");
}
else
if (*serch=='a'&&*(serch+1)=='t'&&*(serch+2)=='a'&&*(serch+3)=='n')
{
pDC->TextOut(6*i+1,1,"atan");
}
else
if (*serch=='a'&&*(serch+1)=='c'&&*(serch+2)=='t'&&*(serch+3)=='g')
{
pDC->TextOut(6*i+1,1,"actg");
}
else
if (*serch=='s'&&*(serch+1)=='i'&&*(serch+2)=='n'&&*(serch+3)=='h')
{
pDC->TextOut(6*i+1,1,"sinh");
}
else
if (*serch=='c'&&*(serch+1)=='o'&&*(serch+2)=='s'&&*(serch+3)=='h')
{
pDC->TextOut(6*i+1,1,"cosh");
}
else
if (*serch=='t'&&*(serch+1)=='a'&&*(serch+2)=='n'&&*(serch+3)=='h')
{
pDC->TextOut(6*i+1,1,"tanh");
}
}//---------------------------------检查用户输入的CString类m_expres里是否有关键字sin,cos等,有则替换为蓝色的字
ReleaseDC(pDC);
}
void CPaint::OnButton1()
{
extern CMyPaintView* dcpoint;
extern double zoom,multi;
extern short bufferx,buffery;
xs=ys=0;
zoom=1.0;
multi=1.0;
bufferx=GetSystemMetrics(SM_CXSCREEN)/2;
buffery=GetSystemMetrics(SM_CYSCREEN)/2;
dcpoint->OnUpdate(NULL,NULL,NULL);
}
BOOL CPaint::OnInitDialog()
{
CDialog::OnInitDialog();
//////////////////////
// TODO: Add extra initialization here
CWnd *m_x=GetDlgItem(IDC_X_ST),
*m_y=GetDlgItem(IDC_Y_ST),
*m_f=GetDlgItem(IDC_F_ST),
*m_p=GetDlgItem(IDC_P_ST),
*m_xexpres=GetDlgItem(IDC_X_EXPRES),
*m_yexpres=GetDlgItem(IDC_Y_EXPRES),
*m_pexpres=GetDlgItem(IDC_EXPRES2),
*m_nexpres=GetDlgItem(IDC_EXPRES),
*m_paintok1=GetDlgItem(ID_PAINT_OK),
*m_paintok2=GetDlgItem(ID_PAINT_OK2),
*m_paintok3=GetDlgItem(ID_PAINT_OK3);
//////////////////////
m_choices.InsertItem(0,"一般方程");
m_choices.InsertItem(1,"参数方程");
m_choices.InsertItem(2,"极坐标方程");////////
m_x->ShowWindow(SW_HIDE);
m_y->ShowWindow(SW_HIDE);
m_f->ShowWindow(SW_SHOW);
m_p->ShowWindow(SW_HIDE);
m_xexpres->ShowWindow(SW_HIDE);
m_yexpres->ShowWindow(SW_HIDE);
m_nexpres->ShowWindow(SW_SHOW);
m_pexpres->ShowWindow(SW_HIDE);
m_paintok1->ShowWindow(SW_SHOW);
m_paintok2->ShowWindow(SW_HIDE);
m_paintok3->ShowWindow(SW_HIDE);
color=myrand();
m_pattern.AddString("实线");
m_pattern.AddString("点线");
m_pattern.SetItemData(0,0);
m_pattern.SetItemData(1,1);
m_pattern.SetCurSel(0);////////////////////////
flag_modify=0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPaint::OnPaintOk()
{
extern CMainFrame* mainwnd;
extern CMyPaintView* dcpoint;
BYTE i;
double yc;
UpdateData();
error=1;
notice=0;
if(m_line_weight<1)
m_line_weight=1;
else
if(m_line_weight>10)
m_line_weight=10;
UpdateData(FALSE);
for(i=0;i<M;part[i++]=0);
if(flag_modify==0)
{
if( ( p1=(MY_LINE*)new (MY_LINE) )==NULL )
goto END;
if(line_count==0)
{
head=p2=p1;
head->next=NULL;
}
else
{
p2->next=p1;
p2=p1;
p2->next=NULL;
}
}
temp=head;
if(m_a<m_b&&line_count<10)
{
if(m_choices.GetCurSel()==1)
OnPaintOk2();
else
if(m_choices.GetCurSel()==2)
OnPaintOk3();
else
{
unsigned short n=0;
for(double xc=m_a;xc<=m_b;xc+=0.05)
{
strncpy(expres,(LPCTSTR)m_expres,M);
yc=-superchge(expres,xc,'x');
if(error!=0)
{
BYTE reset=line_count;
p2=head;
while(reset>1)
{
p2=p2->next;
reset--;
}
if(line_count==0)
p2=head=NULL;
else
p2->next=NULL;
if(flag_modify==0)
delete(p1);
break;
}
if(outrange==1)
{
outrange=0;
notice=1;
continue;
}
if(flag_modify==1)
while(select_line!=0)
{
temp=temp->next;
select_line--;
}
else
temp=p1;
if(fabs(yc-(short)yc)>=0.5)//对舍入误差的处理,使图像平滑
{
if(yc>0)
yc=(short)yc+1;
else
yc=(short)yc-1;
}
else
yc=(short)yc;
temp->point[n].x=(int)xc;
temp->point[n].y=(int)yc;
temp->point[n].z=0;
if(n>1)///////////////去处多余的点
{
CMpoint k1,k2;
k1.x=temp->point[n].x-temp->point[n-1].x;
k1.y=temp->point[n].y-temp->point[n-1].y;
k1.z=temp->point[n].z-temp->point[n-1].z;
k2.x=temp->point[n-1].x-temp->point[n-2].x;
k2.y=temp->point[n-1].y-temp->point[n-2].y;
k2.z=temp->point[n-1].z-temp->point[n-2].z;
if(fabs((k1.x*k2.x+k1.y*k2.y+k1.z*k2.z)/sqrt( (k1.x*k1.x+k1.y*k1.y+k1.z*k1.z)*(k2.x*k2.x+k2.y*k2.y+k2.z*k2.z) )-1.0)<1e-6)
{
temp->point[n-1].x=temp->point[n].x;
temp->point[n-1].y=temp->point[n].y;
temp->point[n-1].z=0;
n=n-1;
n++;
}
else
n++;
}
else
n++;
}
if(error==0)
{
temp->n=n;
temp->tag=0;
temp->real_expres[0]=m_expres;
temp->expres.Format("%s%s 定义域 【%.2f,%.2f】",".F(x)=",m_expres,m_a,m_b);
}
}
if(error==0)
{
temp->m_a=m_a;
temp->m_b=m_b;
temp->color=color;
temp->weight=m_line_weight;
temp->tem_xs=temp->tem_ys=temp->tex_xs=temp->tex_ys=0;
temp->style=m_pattern.GetCurSel();
color=myrand();
UpdateData(FALSE);
OnPaint();
dcpoint->OnUpdate(NULL,NULL,NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -