📄 dialogp.cpp
字号:
// DialogP.cpp : implementation file
//
#include "stdafx.h"
#include "线性分类器.h"
#include "DialogP.h"
#include "线性分类器Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogP dialog
CDialogP::CDialogP(CWnd* pParent /*=NULL*/)
: CDialog(CDialogP::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogP)
m_w1 = _T("");
m_w2 = _T("");
m_w4 = _T("");
//}}AFX_DATA_INIT
}
void CDialogP::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogP)
DDX_Control(pDX, IDOK, m_bo);
DDX_Control(pDX, IDC_STATICf, m_c);
DDX_Control(pDX, IDC_COMBO1, m_com);
DDX_Text(pDX, IDC_EDIT1, m_w1);
DDX_Text(pDX, IDC_EDIT2, m_w2);
DDX_Text(pDX, IDC_EDIT3, m_w4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogP, CDialog)
//{{AFX_MSG_MAP(CDialogP)
ON_WM_ERASEBKGND()
ON_WM_CLOSE()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_CBN_SELENDOK(IDC_COMBO1, OnSelendokCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogP message handlers
BOOL CDialogP::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_w1="1";m_w2="0";m_w4="0";
UpdateData(false);
mybitmap.LoadBitmap(IDB_BITMAP1);
m_com.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDialogP::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(rect);
CDC memdc;
BITMAP bm1;
mybitmap.GetObject(sizeof(BITMAP),&bm1);
memdc.CreateCompatibleDC(pDC);
CBitmap* oldbitmap=memdc.SelectObject(&mybitmap);
pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memdc,0,0,bm1.bmWidth,bm1.bmHeight,SRCCOPY);
return true;
}
void CDialogP::OnClose()
{
// TODO: Add your message handler code here and/or call default
CMyDlg* pp1=(CMyDlg*)GetParent();
pp1->m=m;
pp1->m_b4.down=false;
pp1->m_b4.Invalidate();
CDialog::OnClose();
}
void CDialogP::OnOK()
{
// TODO: Add extra validation here
bool fg=false;
int a1,a2,a3;
a1=atoi(m_w1);
a2=atoi(m_w2);
a3=atoi(m_w4);
double t;
if(a1==0)
{
if((-a3/a2)<0||(-a3/a2)>35)
{
fg=true;
}
}
if(a2==0)
{
if((-a3/a1)<0||(-a3/a1)>35)
{
fg=true;
}
}
if(a1!=0&&a2!=0)
{
t=((double)(-a1))/a2;
if(t>=0)
{
double t1;
if(a2>0)
t1=a2*35+a3;
else
t1=-a2*35-a3;
if(t1<=0) fg=true;
if(a2>0)
t1=a1*35+a3;
else
t1=-a1*35-a3;
if(t1>=0) fg=true;
}
if(t<0)
{
double t2;
if(a2>0)
t2=a3;
else
t2=-a3;
if(t2>=0)fg=true;
if(a2>0)
t2=35*a1+35*a2+a3;
else
t2=-35*a1-35*a2-a3;
if(t2<=0)fg=true;
}
}
if(fg)
{
MessageBox("初始直线越界无法显示","警告",MB_OK | MB_ICONWARNING);
return;
}
CDialog::OnOK();
}
void CDialogP::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
CString temp=m_w1;
UpdateData(true);
if (m_w1.IsEmpty( ))
{
return;
}
if((m_w1=="0")&&(m_w2=="0"))
{
m_w1=temp; UpdateData(false);
return;
}
strcpy(m_c.mychar,"初始函数:");
if(m_w1!="0")
{
if(m_w1!="1")
strcat(m_c.mychar,m_w1);
strcat(m_c.mychar,"X");
}
if(m_w2!="0")
{
if(m_w2.GetAt(0)!='+'&&m_w2.GetAt(0)!='-'&&m_w1!="0")
strcat(m_c.mychar,"+");
if(m_w2!="1")
strcat(m_c.mychar,m_w2);
strcat(m_c.mychar,"Y");
}
if(m_w4!="0")
{
if(m_w4.GetAt(0)!='+'&&m_w4.GetAt(0)!='-')
strcat(m_c.mychar,"+");
strcat(m_c.mychar,m_w4);
}
strcat(m_c.mychar,"=0");
CRect rectlt1;
GetDlgItem(IDC_STATICf)->GetWindowRect(rectlt1);ScreenToClient(rectlt1);
InvalidateRect(rectlt1,true);
// TODO: Add your control notification handler code here
}
void CDialogP::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
CString temp=m_w2;
UpdateData(true);
if (m_w2.IsEmpty( ))
{
return;
}
if((m_w1=="0")&&(m_w2=="0"))
{
m_w2=temp; UpdateData(false);
return;
}
strcpy(m_c.mychar,"初始函数:");
if(m_w1!="0")
{
if(m_w1!="1")
strcat(m_c.mychar,m_w1);
strcat(m_c.mychar,"X");
}
if(m_w2!="0")
{
if(m_w2.GetAt(0)!='+'&&m_w2.GetAt(0)!='-'&&m_w1!="0")
strcat(m_c.mychar,"+");
if(m_w2!="1")
strcat(m_c.mychar,m_w2);
strcat(m_c.mychar,"Y");
}
if(m_w4!="0")
{
if(m_w4.GetAt(0)!='+'&&m_w4.GetAt(0)!='-')
strcat(m_c.mychar,"+");
strcat(m_c.mychar,m_w4);
}
strcat(m_c.mychar,"=0");
CRect rectlt1;
GetDlgItem(IDC_STATICf)->GetWindowRect(rectlt1);ScreenToClient(rectlt1);
InvalidateRect(rectlt1,true);
// TODO: Add your control notification handler code here
}
void CDialogP::OnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
CString temp=m_w4;
UpdateData(true);
if (m_w4.IsEmpty( ))
{
return;
}
if((m_w1=="0")&&(m_w2=="0"))
{
m_w4=temp; UpdateData(false);
return;
}
strcpy(m_c.mychar,"初始函数:");
if(m_w1!="0")
{
if(m_w1!="1")
strcat(m_c.mychar,m_w1);
strcat(m_c.mychar,"X");
}
if(m_w2!="0")
{
if(m_w2.GetAt(0)!='+'&&m_w2.GetAt(0)!='-'&&m_w1!="0")
strcat(m_c.mychar,"+");
if(m_w2!="1")
strcat(m_c.mychar,m_w2);
strcat(m_c.mychar,"Y");
}
if(m_w4!="0")
{
if(m_w4.GetAt(0)!='+'&&m_w4.GetAt(0)!='-')
strcat(m_c.mychar,"+");
strcat(m_c.mychar,m_w4);
}
strcat(m_c.mychar,"=0");
CRect rectlt1;
GetDlgItem(IDC_STATICf)->GetWindowRect(rectlt1);ScreenToClient(rectlt1);
InvalidateRect(rectlt1,true);
// TODO: Add your control notification handler code here
}
void CDialogP::OnSelendokCombo1()
{
// TODO: Add your control notification handler code here
CMyDlg* pp1=(CMyDlg*)GetParent();
pp1->m=m_com.GetCurSel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -