📄 dialogas.cpp
字号:
// DialogAS.cpp : implementation file
//
#include "stdafx.h"
#include "线性分类器.h"
#include "DialogAS.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogAS dialog
#include"MyProgressCtrl.h"
CDialogAS::CDialogAS(CWnd* pParent /*=NULL*/)
: CDialog(CDialogAS::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogAS)
m_w1 = _T("");
m_w2 = _T("");
m_w4 = 0.0;
//}}AFX_DATA_INIT
}
void CDialogAS::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogAS)
DDX_Control(pDX, IDC_BUTTON2, m_b2);
DDX_Control(pDX, IDC_BUTTON3, m_b3);
DDX_Control(pDX, IDC_BUTTON1, m_1);
DDX_Control(pDX, IDC_LIST2, m_l);
DDX_Control(pDX, IDC_LIST1, m_r);
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(CDialogAS, CDialog)
//{{AFX_MSG_MAP(CDialogAS)
ON_WM_ERASEBKGND()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
ON_EN_KILLFOCUS(IDC_EDIT3, OnKillfocusEdit3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogAS message handlers
BOOL CDialogAS::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
mybitmap.LoadBitmap(IDB_BITMAP1);
m_l.SetExtendedStyle (LVS_OWNERDRAWFIXED);
CRect ClientRect;
GetDlgItem(IDC_LIST2)->GetClientRect(&ClientRect);
m_l.InsertColumn (0, " 记录号");
m_l.InsertColumn (1, " W1");
m_l.InsertColumn (2, " W2");
m_l.InsertColumn (3, "增量值");
m_l.SetColumnWidth (0, ClientRect.Width() / 4);
m_l.SetColumnWidth (1, ClientRect.Width() / 4);
m_l.SetColumnWidth (2, ClientRect.Width() / 4);
m_l.SetColumnWidth (3, ClientRect.Width() / 4);
for(int i=0;i<7;i++)
{
m_l.InsertItem (i, " ");
}
GetDlgItem(IDC_LIST1)->GetClientRect(&ClientRect);
m_r.SetExtendedStyle (LVS_OWNERDRAWFIXED);
m_r.InsertColumn (0, " 记录号");
m_r.InsertColumn (1, " W1");
m_r.InsertColumn (2, " W2");
m_r.InsertColumn (3, "增量值");
m_r.InsertColumn (4, "迭代次数");
m_r.InsertColumn (5, " 识别率");
m_r.SetColumnWidth (0, ClientRect.Width() / 6);
m_r.SetColumnWidth (1, ClientRect.Width() / 6);
m_r.SetColumnWidth (2, ClientRect.Width() / 6);
m_r.SetColumnWidth (3, ClientRect.Width() / 6);
m_r.SetColumnWidth (4, ClientRect.Width() / 6);
m_r.SetColumnWidth (5, ClientRect.Width() /6 +3);
for(int i1=0;i1<7;i1++)
{
m_r.InsertItem (i1, " ");
}
rli=0;
m_w4=1.0;
m_w1="1";
m_w2="1";
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDialogAS::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);
int wide=rect.Width()/3;
int mheight=rect.Height()/3;
for (int j=0;j<3;j++)
{
for(int i=0;i<3;i++)
{
pDC->StretchBlt(rect.left,rect.top,wide,mheight,&memdc,0,0,bm1.bmWidth,bm1.bmHeight,SRCCOPY);
rect.left+= wide;
}
rect.left-=wide*3;
rect.top+=mheight;
}
return true;
}
void CDialogAS::OnButton1()
{
// TODO: Add your control notification handler code here
CMyProgressCtrl myprogress;
AfxGetApp()->BeginWaitCursor();
CRect rect,rect1;
GetClientRect(rect);
int temp=rect.left+rect.Width()/2;
rect.left=temp-250;
rect.right=temp+250;
GetDlgItem(IDC_BUTTON1)->GetWindowRect(rect1);
ScreenToClient(rect1);
rect.top=rect1.top-50;
rect.bottom=rect.top+20;
myprogress.Create(WS_CHILD|WS_VISIBLE,rect,this,1820);
myprogress.SetRange(0,200);
myprogress.SetPos(10);
double w1,w2,w4;
for(int i1=0;i1<rli;i1++)
{
w1=(double)atoi(m_l.GetItemText(i1,1));
w2=(double)atoi(m_l.GetItemText(i1,2));
w4=0;
double a=atof(m_l.GetItemText(i1,3));
if(w2<=0)
{
w1=-w1;
w2=-w2;w4=-w4;
}
bool fe=true;
bool ft=true;
int count=0;
int t1=0;
while(fe)
{
////////////////////////////////////////
for(int t=0;t<100;t++)
{
ft=true;
if(t%2==0)
{
double xt,yt,z;
xt=((double)(*(onep+t)))/10;
yt=((double)(*(onep+t+1)))/10;
z=xt*w1+yt*w2+w4;
if(z<=0)
{
ft=false;
w1=w1+a*xt;
w2=w2+a*yt;
w4=w4+a;
}
}
else
{
double xt,yt,z;
xt=((double)(*(towp+(t-1))))/10;
yt=((double)(*(towp+t)))/10;
z=xt*w1+yt*w2+w4;
if(z>=0)
{
ft=false;
w1=w1-a*xt;
w2=w2-a*yt;
w4=w4-a;
}
}
}
if(ft)
{
fe=false;
}
////////////////////////////////////////
count++;
}
//////////////////////////////
myprogress.SetPos(200*i1/rli+200*3/(rli*4));
Sleep(500);
t1=0;
for(int i=0;i<200;i++)
{
double xt,yt,z;
if(i<100)
{
xt=((double)(*(onetp+2*i)))/10;
yt=((double)(*(onetp+2*i+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z<=0)
{
t1++;
}
}
else
{
if(i<200)
{
xt=((double)(*(towtp+2*(i-100))))/10;
yt=((double)(*(towtp+2*(i-100)+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z>=0)
{
t1++;
}
}
}
}
CString strData;
strData.Format("%d", i1+1);
CString cc;
cc.Format("%d", count);
CString temp;
double rate;
rate=((double)(200-t1))/200;
int intn=int(rate*100);
temp.Format("%d", intn);
temp=temp+".";
CString temp1;
int dot=int(rate*100000-intn*1000+0.5);
temp1.Format("%d", dot);
temp=temp+temp1+"%";
///////////////////////////////
m_r.falg2=true;
myprogress.SetPos(200*i/rli+200/(rli));
m_r.SetItemText (i1, 0, strData);
m_r.SetItemText (i1, 1, m_l.GetItemText(i1,1));
m_r.SetItemText (i1, 2, m_l.GetItemText(i1,2));
m_r.SetItemText (i1, 3, m_l.GetItemText(i1,3));
m_r.SetItemText (i1, 4, cc);
m_r.SetItemText (i1, 5, temp);
}
AfxGetApp()->EndWaitCursor();
}
void CDialogAS::OnButton2()
{
// TODO: Add your control notification handler code here
if(rli==7)
{
rli=0;
for(int i=0;i<7;i++)
{
m_l.SetItemText (i, 0, " ");
m_l.SetItemText (i, 1, "");
m_l.SetItemText (i, 2, "");
m_l.SetItemText (i, 3, "");
}
}
CString tfl;
tfl.Format("%f",m_w4);
CString strData;
strData.Format("%d", rli+1);
m_l.SetItemText (rli, 0, strData);
m_l.SetItemText (rli, 1, m_w1);
m_l.SetItemText (rli, 2, m_w2);
m_l.SetItemText (rli, 3, tfl);
rli++;
}
void CDialogAS::OnButton3()
{
// TODO: Add your control notification handler code here
for(int i=0;i<7;i++)
{
m_l.SetItemText (i, 0, " ");
m_l.SetItemText (i, 1, "");
m_l.SetItemText (i, 2, "");
m_l.SetItemText (i, 3, "");
m_r.SetItemText (i, 0, " ");
m_r.SetItemText (i, 1, "");
m_r.SetItemText (i, 2, "");
m_r.SetItemText (i, 3, " ");
m_r.SetItemText (i, 4, "");
m_r.SetItemText (i, 5, "");
}
rli=0;
}
void CDialogAS::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=="0")&&(m_w2=="0"))
{
m_w1=temp; UpdateData(false);
}
// TODO: Add your control notification handler code here
}
void CDialogAS::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_w1=="0")&&(m_w2=="0"))
{
m_w2=temp; UpdateData(false);
}
// TODO: Add your control notification handler code here
}
void CDialogAS::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.
double tp=m_w4;
UpdateData(true);
if(m_w4==0)
{
m_w4=tp; UpdateData(false);
}
// TODO: Add your control notification handler code here
}
void CDialogAS::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
if (m_w1.IsEmpty( ))
{
m_w1="1";UpdateData(false);
}
}
void CDialogAS::OnKillfocusEdit2()
{
// TODO: Add your control notification handler code here
if (m_w2.IsEmpty( ))
{
m_w2="0";UpdateData(false);
}
}
void CDialogAS::OnKillfocusEdit3()
{
// TODO: Add your control notification handler code here
if (m_w4==0)
{
m_w4=1;UpdateData(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -