⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogs.cpp

📁 该程序是一个对于一个对于以某一直线为边界的两类进行分类
💻 CPP
字号:
// DialogS.cpp : implementation file
//

#include "stdafx.h"
#include "线性分类器.h"
#include "DialogS.h"
#include "线性分类器Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include"MyProgressCtrl.h"
/////////////////////////////////////////////////////////////////////////////
// CDialogS dialog


CDialogS::CDialogS(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogS::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogS)
	m_w1 = _T("");
	m_w2 = _T("");
	//}}AFX_DATA_INIT
    DAS=new CDialogAS(this);
DMS=new CDialogMS(this);
DCS=new CDialogCS(this);
}


void CDialogS::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogS)
	DDX_Control(pDX, IDC_BUTTONB4, m_b4);
	DDX_Control(pDX, IDC_BUTTONB3, m_b3);
	DDX_Control(pDX, IDC_BUTTONB2, m_b2);
	DDX_Control(pDX, IDC_BUTTON3, m_cl);
	DDX_Control(pDX, IDOK, m_b1);
	DDX_Control(pDX, IDC_BUTTON2, m_add);
	DDX_Control(pDX, IDC_BUTTON1, m_st);
	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);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogS, CDialog)
	//{{AFX_MSG_MAP(CDialogS)
	ON_WM_ERASEBKGND()
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
	ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTONB2, OnButtonb2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTONB3, OnButtonb3)
	ON_BN_CLICKED(IDC_BUTTONB4, OnButtonb4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogS message handlers

BOOL CDialogS::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.SetColumnWidth (0, ClientRect.Width() / 3);
    m_l.SetColumnWidth (1, ClientRect.Width() / 3);
    m_l.SetColumnWidth (2, ClientRect.Width() / 3);
    
    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.SetColumnWidth (0, ClientRect.Width() / 5);
    m_r.SetColumnWidth (1, ClientRect.Width() / 5);
    m_r.SetColumnWidth (2, ClientRect.Width() / 5);
    m_r.SetColumnWidth (3, ClientRect.Width() / 5);
    m_r.SetColumnWidth (4, ClientRect.Width() / 5);
    
for(int i1=0;i1<7;i1++)
	{
	m_r.InsertItem (i1, " ");
	}
rli=0;
DAS->Create(IDD_OLE_PROPPAGE_LARGE, this);
DMS->Create(IDD_OLE_PROPPAGE_LARGE1, this);
DCS->Create(IDD_OLE_PROPPAGE_LARGE2, this);
	///////////////////////////////
for(int i11=0;i11<100;i11++)
	{
       DAS->onep[i11]=onep[i11];
       DAS->towp[i11]=towp[i11];
	}
	for(int i2=0;i2<200;i2++)
	{
       DAS->onetp[i2]=onetp[i2];
       DAS->towtp[i2]=towtp[i2];
	}
for(int i111=0;i111<100;i111++)
	{
       DMS->onep[i111]=onep[i111];
       DMS->towp[i111]=towp[i111];
	}
	for(int i21=0;i21<200;i21++)
	{
       DMS->onetp[i21]=onetp[i21];
       DMS->towtp[i21]=towtp[i21];
	}
for(int i1111=0;i1111<100;i1111++)
	{
       DMS->onep[i1111]=onep[i1111];
       DMS->towp[i1111]=towp[i1111];
	}
	for(int i211=0;i211<200;i211++)
	{
       DMS->onetp[i211]=onetp[i211];
       DMS->towtp[i211]=towtp[i211];
	}
for(int i11111=0;i11111<100;i11111++)
	{
       DCS->onep[i11111]=onep[i11111];
       DCS->towp[i11111]=towp[i11111];
	}
	for(int i2111=0;i2111<200;i2111++)
	{
       DCS->onetp[i2111]=onetp[i2111];
       DCS->towtp[i2111]=towtp[i2111];
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CDialogS::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	    CRect rect,rects;
		GetClientRect(rect);
        GetDlgItem(IDC_STATIC1)->GetClientRect(rects);
	    for(int i=0;i<15;i++)
		{
          rects.top=rect.top+i*3;
		  rects.bottom=rects.top+3;
          pDC->FillSolidRect(rects,RGB(188+i,212+i,249));
		}
        rect.top=rects.bottom;
//////////////////////////////////////////////////////
        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 CDialogS::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);
	  

  }
    
 
      return;
	// TODO: Add your control notification handler code here
	
}

void CDialogS::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.
	
	// TODO: Add your control notification handler code here
    CString temp=m_w2;
	UpdateData(true);
	if((m_w1=="0")&&(m_w2=="0"))
  
	{
	  m_w2=temp;	UpdateData(false);
	  

  }
      return;
}

void CDialogS::OnKillfocusEdit1() 
{
	// TODO: Add your control notification handler code here
	if (m_w1.IsEmpty( ))
	{
		m_w1="0";UpdateData(false);
	}
}

void CDialogS::OnKillfocusEdit2() 
{
	// TODO: Add your control notification handler code here
	if (m_w2.IsEmpty( ))
	{
		m_w2="0";UpdateData(false);
	}
}

void CDialogS::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, "");
	   }
	}
	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);
	rli++;

}

void CDialogS::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_r.SetItemText (i, 0, " ");
    m_r.SetItemText (i, 1, "");
    m_r.SetItemText (i, 2, "");
m_r.SetItemText (i, 3, " ");
    m_r.SetItemText (i, 4, "");
   
	   }
	rli=0;
}

void CDialogS::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CMyDlg* pp1=(CMyDlg*)GetParent();
	pp1->m_b7.down=false;
	pp1->m_b7.Invalidate();
	CDialog::OnClose();
}

void CDialogS::OnButtonb2() 
{
	// TODO: Add your control notification handler code here
	
	m_b1.down=false;
	m_b1.Invalidate();
m_b3.down=false;
	m_b3.Invalidate();
for(int i=0;i<7;i++)
	   {
	      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, "");
	   }
	CRect rect,rect1;
	 GetClientRect(rect);
     //ScreenToClient(rect);
     GetDlgItem(IDC_STATIC1)->GetClientRect(rect1);
 
int w=rect.bottom-rect1.bottom;



DAS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_SHOWWINDOW);	 
DMS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);	
DCS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);
}

void CDialogS::OnOK() 
{
	// TODO: Add extra validation here
	m_b2.down=false;
	m_b2.Invalidate();
m_b3.down=false;
	m_b3.Invalidate();
m_b4.down=false;
	m_b4.Invalidate();
	CRect rect,rect1;
	 GetClientRect(rect);
     //ScreenToClient(rect);
     GetDlgItem(IDC_STATIC1)->GetClientRect(rect1);
 
int w=rect.bottom-rect1.bottom;
	DAS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);	
	DMS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);	
DCS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);
}

void CDialogS::OnButton1() 
{
	// TODO: Add your control notification handler code here
    /* m_r.SetItemText (0, 0, "1");
    m_r.SetItemText (0, 1, m_l.GetItemText(0,1));
    m_r.SetItemText (0, 2, m_l.GetItemText(0,1));*/
	//mr.r
	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;
	  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+1*xt;
				        w2=w2+1*yt;
				        w4=w4+1;
					  }
				 }
				 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-1*xt;
				          w2=w2-1*yt;
				          w4=w4-1;
				
				 
					   }
				 }
				 
			 }
             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, cc);
 m_r.SetItemText (i1, 4, temp);  
   }
AfxGetApp()->EndWaitCursor();  
  
}

void CDialogS::OnButtonb3() 
{
	// TODO: Add your control notification handler code here
m_b1.down=false;
	m_b1.Invalidate();
m_b2.down=false;
	m_b2.Invalidate();
m_b4.down=false;
	m_b4.Invalidate();
	CRect rect,rect1;
	 GetClientRect(rect);
     //ScreenToClient(rect);
     GetDlgItem(IDC_STATIC1)->GetClientRect(rect1);
 
int w=rect.bottom-rect1.bottom;



DMS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_SHOWWINDOW);	 
DAS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);
DCS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);	
}

void CDialogS::OnButtonb4() 
{
	// TODO: Add your control notification handler code here
	m_b1.down=false;
	m_b1.Invalidate();
m_b2.down=false;
	m_b2.Invalidate();
m_b3.down=false;
	m_b3.Invalidate();
	CRect rect,rect1;
	 GetClientRect(rect);
     //ScreenToClient(rect);
     GetDlgItem(IDC_STATIC1)->GetClientRect(rect1);
 
int w=rect.bottom-rect1.bottom;



DCS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_SHOWWINDOW);	 
DAS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);	
DMS->SetWindowPos(&wndTop, rect.left, rect1.bottom,rect.Width(),w, SWP_HIDEWINDOW);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -