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

📄 dialogs1.cpp

📁 本程序是一个最近邻分类算法的演示程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Dialogs1.cpp : implementation file
//

#include "stdafx.h"
#include "最近邻法分类器.h"
#include "Dialogs1.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogs1 dialog


CDialogs1::CDialogs1(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogs1::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogs1)
	m_e = 0;
	//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON9);
}


void CDialogs1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogs1)
	DDX_Control(pDX, IDC_LIST1, m_2);
	DDX_Control(pDX, IDC_LIST2, m_1);
	DDX_Control(pDX, IDC_STATIC5, m_c3);
	DDX_Control(pDX, IDC_STATIC2, m_c1);
	DDX_Control(pDX, IDC_STATIC4, m_c2);
	DDX_Text(pDX, IDC_EDIT1, m_e);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogs1, CDialog)
	//{{AFX_MSG_MAP(CDialogs1)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogs1 message handlers

BOOL CDialogs1::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	int cx, cy; 
    HDC dc = ::GetDC(NULL); 
   cx = GetDeviceCaps(dc,HORZRES) + 
        GetSystemMetrics(SM_CXBORDER); 
    cy = GetDeviceCaps(dc,VERTRES) +
        GetSystemMetrics(SM_CYBORDER)-20; 
    ::ReleaseDC(0,dc); //
    ::SetWindowPos(m_hWnd, HWND_TOPMOST, 
        -(GetSystemMetrics(SM_CXBORDER)+1), 
        -(GetSystemMetrics(SM_CYBORDER)+1), 
        cx+1,cy+1, SWP_NOZORDER);
	mybitmap.LoadBitmap(IDB_BITMAP1);
    int temph,tempw;
	CRect rect1,rect2,rect,rect3,rect4,rect5,rect6,rect7,rt1,rt2,rt3;GetClientRect(rect);
   GetDlgItem(IDC_STATIC1)->GetWindowRect(rect1);ScreenToClient(rect1);
  rect1.left=rect.left+20;
  rect1.right=rect.right-450;
  rect1.top=rect.top+20;
rect1.bottom =rect1.top+299;
 GetDlgItem(IDC_STATIC1)->MoveWindow(rect1,true);
 GetDlgItem(IDC_STATIC4)->GetWindowRect(rt1);ScreenToClient(rt1);
  rt1.left=rect.left+50;
  rt1.right=rt1.left+120;
  rt1.top=rect1.bottom+10;
rt1.bottom =rt1.top+25;
 GetDlgItem(IDC_STATIC4)->MoveWindow(rt1,true);
GetDlgItem(IDC_STATIC3)->GetWindowRect(rt2);ScreenToClient(rt2);
  rt2.left=rect.left+20;
  rt2.right=rect.right-450;
  rt2.top=rt1.bottom+10;
rt2.bottom=rt2.top+299;
 GetDlgItem(IDC_STATIC3)->MoveWindow(rt2,true);
GetDlgItem(IDC_STATIC5)->GetWindowRect(rt3);ScreenToClient(rt3);
  rt3.left=rect.left+50;
  rt3.right=rt3.left+120;
  rt3.top=rt2.bottom+10;
rt3.bottom =rt3.top+25;
 GetDlgItem(IDC_STATIC5)->MoveWindow(rt3,true);
/* GetDlgItem(IDC_STATIC2)->GetWindowRect(rect2);ScreenToClient(rect2);
tempw=rect2.Width();temph=rect2.Height();
rect2.left= rect1.right+10;
rect2.right=rect2.left+tempw;
 rect2.top=rect.top+20;
rect2.bottom =rect2.top+temph;
GetDlgItem(IDC_STATIC2)->MoveWindow(rect2,true);*/

/*GetDlgItem(IDC_EDIT1)->GetWindowRect(rect3);ScreenToClient(rect3);
tempw=rect3.Width();temph=rect3.Height();
rect3.left= rect2.right+10;
rect3.right=rect3.left+tempw;
 rect3.top=rect.top+20;
rect3.bottom =rect3.top+temph;
GetDlgItem(IDC_EDIT1)->MoveWindow(rect3,true);
GetDlgItem(IDOK1)->GetWindowRect(rect4);ScreenToClient(rect4);
tempw=rect4.Width();temph=rect4.Height();
rect4.left= rect1.right+(rect.right-rect1.right)/2-tempw/2;
rect4.right=rect4.left+tempw;
 rect4.top=rect2.bottom+10;
rect4.bottom =rect4.top+temph;
GetDlgItem(IDOK1)->MoveWindow(rect4,true);*/
GetDlgItem(IDC_LIST2)->GetWindowRect(rect5);ScreenToClient(rect5);
tempw=rect5.Width();temph=rect5.Height();
rect5.left= rect1.right+(rect.right-rect1.right)/2-tempw/2;
rect5.right=rect5.left+tempw;
 rect5.top=rect4.bottom+10;
rect5.bottom =rect5.top+temph;
GetDlgItem(IDC_LIST2)->MoveWindow(rect5,true);
GetDlgItem(IDOK2)->GetWindowRect(rect6);ScreenToClient(rect6);
tempw=rect6.Width();temph=rect6.Height();
rect6.left= rect1.right+(rect.right-rect1.right)/2-tempw/2;
rect6.right=rect6.left+tempw;
 rect6.top=rect.top+20;;
rect6.bottom =rect6.top+temph;
GetDlgItem(IDOK2)->MoveWindow(rect6,true);
GetDlgItem(IDC_LIST1)->GetWindowRect(rect7);ScreenToClient(rect7);
tempw=rect7.Width();temph=rect7.Height();
rect7.left= rect1.right+(rect.right-rect1.right)/2-tempw/2;
rect7.right=rect7.left+tempw;
 rect7.top=rect6.bottom+50;
rect7.bottom =rect7.top+2*temph-140;
GetDlgItem(IDC_LIST1)->MoveWindow(rect7,true);
//strcpy(m_c1.mychar,"输入k的值:");
strcpy(m_c2.mychar,"k值对正确率的影响曲线");
strcpy(m_c3.mychar,"k值对运行时间的影响曲线");
m_2.SetExtendedStyle (LVS_OWNERDRAWFIXED);
CRect ClientRect;
    GetDlgItem(IDC_LIST1)->GetClientRect(&ClientRect);
    m_2.InsertColumn (0, "k的取值");
    m_2.InsertColumn (1, "准确率");
    m_2.InsertColumn (2, "错误率");
    m_2.InsertColumn (3, "运行时间");
   
    m_2.SetColumnWidth (0, ClientRect.Width() / 4);
    m_2.SetColumnWidth (1, ClientRect.Width() / 4);
    m_2.SetColumnWidth (2, ClientRect.Width() / 4);
    m_2.SetColumnWidth (3, LVSCW_AUTOSIZE_USEHEADER+130);
    for(int i=0;i<20;i++)
	{
	m_2.InsertItem (i, " ");
	}
m_1.SetExtendedStyle (LVS_OWNERDRAWFIXED);
//CRect ClientRect;
    GetDlgItem(IDC_LIST2)->GetClientRect(&ClientRect);
    m_1.InsertColumn (0, "记录数");
    m_1.InsertColumn (1, "k的取值");
   
   
    m_1.SetColumnWidth (0, ClientRect.Width() / 2);
    
    m_1.SetColumnWidth (1, LVSCW_AUTOSIZE_USEHEADER);
    for(int i1=0;i1<20;i1++)
	{
	m_1.InsertItem (i1, " ");
	}
	number=0;f1=false;f2=false;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogs1::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

BOOL CDialogs1::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()/4;
		int mheight=rect.Height()/4;
	for (int j=0;j<4;j++)
	{
		for(int i=0;i<4;i++)
	{
      pDC->StretchBlt(rect.left,rect.top,wide,mheight,&memdc,0,0,bm1.bmWidth,bm1.bmHeight,SRCCOPY);
        rect.left+= wide;	
	}
	     rect.left-=wide*4;
		 rect.top+=mheight;
	}
CRect rectp,rectp1; 
	CPen *pOldPen;
	GetDlgItem(IDC_STATIC1)->GetWindowRect(rectp);ScreenToClient(rectp);
	pDC->FillSolidRect(rectp,RGB(255,255,255));
GetDlgItem(IDC_STATIC3)->GetWindowRect(rectp1);ScreenToClient(rectp1);
	pDC->FillSolidRect(rectp1,RGB(255,255,255));
	CPen mypen1(PS_SOLID,1,RGB(0,0,0));
   pOldPen=pDC->SelectObject(&mypen1);
   pDC->MoveTo(rectp.left+20, rectp.bottom-20);
   pDC->LineTo(rectp.left+20, rectp.bottom-290);
   pDC->LineTo(rectp.left+15, rectp.bottom-275);
   pDC->MoveTo(rectp.left+20, rectp.bottom-290);
   pDC->LineTo(rectp.left+25, rectp.bottom-275);
   pDC->TextOut(rectp.left, rectp.bottom-290,"准");
pDC->TextOut(rectp.left, rectp.bottom-260,"确");
pDC->TextOut(rectp.left, rectp.bottom-230,"率");
pDC->MoveTo(rectp.left+20, rectp.bottom-20);
pDC->LineTo(rectp.left+20+400, rectp.bottom-20);
pDC->LineTo(rectp.left+20+385, rectp.bottom-25);
pDC->MoveTo(rectp.left+20+400, rectp.bottom-20);
pDC->LineTo(rectp.left+20+385, rectp.bottom-15);
pDC->TextOut(rectp.left+20+405,rectp.bottom-20,"k坐标");
pDC->MoveTo(rectp1.left+20, rectp1.bottom-20);
   pDC->LineTo(rectp1.left+20, rectp1.bottom-290);
   pDC->LineTo(rectp1.left+15, rectp1.bottom-275);
   pDC->MoveTo(rectp1.left+20, rectp1.bottom-290);
   pDC->LineTo(rectp1.left+25, rectp1.bottom-275);
   pDC->TextOut(rectp1.left, rectp1.bottom-290,"运");
pDC->TextOut(rectp1.left, rectp1.bottom-260,"行");
pDC->TextOut(rectp1.left, rectp1.bottom-230,"时");
pDC->TextOut(rectp1.left, rectp1.bottom-200,"间");
pDC->MoveTo(rectp1.left+20, rectp1.bottom-20);
pDC->LineTo(rectp1.left+20+400, rectp1.bottom-20);
pDC->LineTo(rectp1.left+20+385, rectp1.bottom-25);
pDC->MoveTo(rectp1.left+20+400, rectp1.bottom-20);
pDC->LineTo(rectp1.left+20+385, rectp1.bottom-15);
pDC->TextOut(rectp1.left+20+405,rectp1.bottom-20,"k坐标");

if(f1)
{
	int i;
	double a1=0,a2=0,a3=0;
	double t1=0,t2=0;
	CPoint lp[19]; 
	for(i=0;i<19;i++)
	{
       int k=res[i];
		lp[i].x=rectp.left+20+k;
	    lp[i].y=rectp.bottom-20-int(zt[k-1]/0.004);
	}
	/*for(i=0;i<4;i++)
	{
       lp[i].x=rectp1.left+20+50*i;
	   lp[i].y=rectp1.bottom-20-50*4+50*i;
	}*/
CPen mypen2(PS_SOLID,2,RGB(255,0,0));
pDC->SelectObject(&mypen2);
pDC->PolyBezier(lp,19);

/////////////////////////////////////////////////
	double max=0;
for(i=0;i<20;i++)
{
	if(max<ztm[i])max=ztm[i];
}
for(i=0;i<19;i++)
	{
       int k=res[i];
		lp[i].x=rectp1.left+20+k;
	    lp[i].y=rectp1.bottom-20-int(ztm[i]*250/max);
	}
pDC->PolyBezier(lp,19);
/////////////////////////////////////////////////

}
pDC->SelectObject(pOldPen);	
return true;
}

BEGIN_EVENTSINK_MAP(CDialogs1, CDialog)
    //{{AFX_EVENTSINK_MAP(CDialogs1)
	ON_EVENT(CDialogs1, IDOK1, 1 /* Click */, OnClickOk1, VTS_NONE)
	ON_EVENT(CDialogs1, IDOK2, 1 /* Click */, OnClickOk2, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CDialogs1::OnClickOk1() 
{
	// TODO: Add your control notification handler code here
	if(number==12)
	{
		number=0;
       for(int i=0;i<14;i++)
	   {
	       m_1.SetItemText (i, 0, " ");
           m_1.SetItemText (i, 1, "");
	        res[i]=0;
    
	   }
	}
	CString tfl;
tfl.Format("%d",m_e); 

		CString    strData;
    strData.Format("%d", number+1); 
    m_1.SetItemText (number, 0, strData);
    m_1.SetItemText (number, 1, tfl);
    res[number]=m_e;
	number++;
}

void CDialogs1::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.
	UpdateData(true);
	// TODO: Add your control notification handler code here
	
}

void CDialogs1::OnClickOk2() 
{
	// TODO: Add your control notification handler code here
	int re=20;

⌨️ 快捷键说明

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