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

📄 k均值dlg.cpp

📁 本程序通过k均值算法对两类进行分类。通过任意选择初始点
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// K均值Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "K均值.h"
#include "K均值Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKDlg dialog

CKDlg::CKDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CKDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CKDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CKDlg)
	DDX_Control(pDX, IDC_STATICT5, m_t5);
	DDX_Control(pDX, IDC_STATICT4, m_t4);
	DDX_Control(pDX, IDC_STATICT3, m_t3);
	DDX_Control(pDX, IDC_STATICT2, m_t2);
	DDX_Control(pDX, IDC_STATICT1, m_t1);
	DDX_Control(pDX, IDC_BUTTON2, m_b2);
	DDX_Control(pDX, IDC_BUTTON1, m_b1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CKDlg, CDialog)
	//{{AFX_MSG_MAP(CKDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONDOWN()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKDlg message handlers

BOOL CKDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	mybitmap.LoadBitmap(IDB_BITMAP1);
    CRect rect,rects,rects1,rectp,rects2,rectT1,rectT2,rectT3,rectT4,rectT5;
	int tempw,temph;
	GetClientRect(rect);
    GetDlgItem(IDC_STATIC1)->GetClientRect(rects);
	temph=rects.Height();
	rects.left=rect.left;
    rects.right=rect.right;
	rects.top=rect.top;
	rects.bottom=rect.top+temph;
    GetDlgItem(IDC_STATIC1)->MoveWindow(rects,true);
CRect rt1,rt2,rt3,rt4,rt5,rt6,rt7;
	GetDlgItem(IDC_BUTTON1)->GetWindowRect(rt1);ScreenToClient(rt1);
	tempw=rt1.Width();
	rt1.top=rects.top+10;
    rt1.bottom=rects.bottom-10;
	rt1.left=rect.left+6;
	rt1.right=rt1.left+tempw;
    GetDlgItem(IDC_BUTTON1)->MoveWindow(rt1,true);
GetDlgItem(IDC_BUTTON2)->GetWindowRect(rt2);ScreenToClient(rt2);
	tempw=rt2.Width();
	rt2.top=rects.top+10;
    rt2.bottom=rects.bottom-10;
	rt2.left=rt1.right+6;
	rt2.right=rt2.left+tempw;
    GetDlgItem(IDC_BUTTON2)->MoveWindow(rt2,true);
rectp.top=rects.bottom+30;
	rectp.bottom=rectp.top+500;
	rectp.left=rect.left+10;
	rectp.right=rectp.left+500;
	GetDlgItem(IDC_STATIC2)->MoveWindow(rectp,true);
rects2.left=rectp.right+30;
	rects2.right=rect.right-10;
	rects2.top=rects.bottom+30;
	rects2.bottom=rectp.top+500;
    GetDlgItem(IDC_STATIC3)->MoveWindow(rects2,true);
   rectT1.left=rectp.right+40;
	rectT1.right=rect.right-20;
	rectT1.top=rects2.top+30;
	rectT1.bottom=rectT1.top+20;
GetDlgItem(IDC_STATICT1)->MoveWindow(rectT1,true);
 rectT2.left=rectp.right+40;
	rectT2.right=rect.right-20;
	rectT2.top=rectT1.bottom+30;
	rectT2.bottom=rectT2.top+20;
GetDlgItem(IDC_STATICT2)->MoveWindow(rectT2,true);
rectT3.left=rectp.right+40;
	rectT3.right=rect.right-20;
	rectT3.top=rectT2.bottom+30;
	rectT3.bottom=rectT3.top+20;
GetDlgItem(IDC_STATICT3)->MoveWindow(rectT3,true);
rectT4.left=rectp.right+40;
	rectT4.right=rect.right-20;
	rectT4.top=rectT3.bottom+30;
	rectT4.bottom=rectT4.top+20;
GetDlgItem(IDC_STATICT4)->MoveWindow(rectT4,true);
rectT5.left=rectp.right+40;
	rectT5.right=rect.right-20;
	rectT5.top=rectT4.bottom+30;
	rectT5.bottom=rectT5.top+20;
GetDlgItem(IDC_STATICT5)->MoveWindow(rectT5,true);
strcpy(m_t1.mychar,"两类中心点坐标:");flag=false;
dot=false;dot1=false;dot2=false;z=0;
point[0]=0;point[1]=0;point[2]=0;point[3]=1;point[4]=0;point[5]=2;point[6]=1;point[7]=0;point[8]=1;point[9]=2;point[10]=2;point[11]=0;point[12]=2;point[13]=1;point[14]=2;point[15]=2;point[16]=7;point[17]=6;point[18]=7;point[19]=7;point[20]=7;point[21]=8;point[22]=8;point[23]=6;point[24]=8;point[25]=7;point[26]=8;point[27]=8;point[28]=8;point[29]=9;point[30]=9;point[31]=7;point[32]=9;point[33]=8;point[34]=9;point[35]=9;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CKDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CKDlg::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();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CKDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL CKDlg::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
		GetClientRect(rect);
       
        
//////////////////////////////////////////////////////
        CDC memdc;

⌨️ 快捷键说明

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