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

📄 homeconfig.cpp

📁 机械手IPC控制器伺服运动程序
💻 CPP
字号:
// HomeConfig.cpp : implementation file
//

#include "stdafx.h"
#include "alfa.h"
#include "HomeConfig.h"
#include "Main.h"
#include "io.h"
#define DATA_FILE _T("channel.bkp")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHomeConfig dialog


CHomeConfig::CHomeConfig(CWnd* pParent /*=NULL*/)
	: CDialog(CHomeConfig::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHomeConfig)
	m_mode = 3;
	m_index = 0;
	m_highspd = 10;
	m_lowspd = 10;
	m_acc = 300.0f;
	m_dec = 300.0f;
	m_offset = 0.0;
	m_channel = 0;
	m_direction = 0;
	m_sensor = 0;
	//}}AFX_DATA_INIT
}


void CHomeConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHomeConfig)
	DDX_Control(pDX, IDC_EDIT7, m_edt7);
	DDX_Control(pDX, IDC_EDIT6, m_edt6);
	DDX_Control(pDX, IDC_EDIT5, m_edt5);
	DDX_Control(pDX, IDC_EDIT4, m_edt4);
	DDX_Control(pDX, IDC_EDIT3, m_edt3);
	DDX_Control(pDX, IDC_EDIT2, m_edt2);
	DDX_Control(pDX, IDC_EDIT1, m_edt1);
	DDX_Text(pDX, IDC_EDIT1, m_mode);
	DDX_Text(pDX, IDC_EDIT2, m_index);
	DDX_Text(pDX, IDC_EDIT3, m_highspd);
	DDX_Text(pDX, IDC_EDIT4, m_lowspd);
	DDX_Text(pDX, IDC_EDIT5, m_acc);
	DDX_Text(pDX, IDC_EDIT6, m_dec);
	DDX_Text(pDX, IDC_EDIT7, m_offset);
	DDX_CBIndex(pDX, IDC_COMBO1, m_channel);
	DDX_CBIndex(pDX, IDC_COMBO2, m_direction);
	DDX_CBIndex(pDX, IDC_COMBO3, m_sensor);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CHomeConfig, CDialog)
	//{{AFX_MSG_MAP(CHomeConfig)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_SHOWWINDOW()
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo1)
	ON_BN_CLICKED(IDC_BUTTON1, OnBtnOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHomeConfig message handlers

void CHomeConfig::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CMain * main=(CMain *)GetParent();
	ShowWindow(FALSE);
	main->dlgsysparamsel->ShowWindow(TRUE);
}

void CHomeConfig::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	if(bShow!=1) return;
	CMain * main=(CMain *)GetParent();
	main->dlgcur=this;
	LoadRecords();
	OnSelchangeCombo1();
}

BOOL CHomeConfig::CanSerialize()
{
   return(0==_access(DATA_FILE,1));
}

void CHomeConfig::Serialize(CArchive& ar) 
{
	m_channels.Serialize(ar);
}

void CHomeConfig::LoadRecords()
{
  if(CanSerialize())
  {
	  CFile file;
	  CFileException fe;
	  if(file.Open(DATA_FILE,CFile::modeRead|CFile::typeBinary,&fe))
	  {
		  CArchive ar(&file,CArchive::load);
		  Serialize(ar);
	  }
  }
}

void CHomeConfig::SaveRecords()
{
    UINT flag=CFile::modeWrite|CFile::typeBinary;
	BOOL canSave=FALSE;
	if(_access(DATA_FILE,0))
	{
		flag|=CFile::modeCreate;
		canSave=TRUE;
	}
	else
		canSave=CanSerialize();
	if(canSave)
	{
		CFile file;
		CFileException fe;
		if(file.Open(DATA_FILE,flag,&fe))
		{
			CArchive ar(&file,CArchive::store);
			Serialize(ar);
		}
	}
}

void CHomeConfig::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	Cchannel * pchannel=NULL;
	if(m_channels.Lookup(m_channel,pchannel))
	{
		if(pchannel)
		{
			m_direction=pchannel->m_direction ;
			m_sensor=pchannel->m_sensor ;
			m_offset=pchannel->m_offset ;
			m_acc=pchannel->m_acc ;
			m_dec=pchannel->m_dec;
			m_highspd=pchannel->m_highspd;
			m_lowspd=pchannel->m_lowspd;
			m_index=pchannel->m_index;
			m_mode=pchannel->m_mode;
			UpdateData(FALSE);
		}
	}
}

void CHomeConfig::OnDropdownCombo1() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	Cchannel * pchannel=NULL;
	if(!m_channels.Lookup(m_channel,pchannel))
	{
		pchannel=new Cchannel;
		m_channels.SetAt(m_channel,pchannel);
	}
	if(pchannel)
	{
		pchannel->m_channel=m_channel;
		pchannel->m_mode=m_mode;
		pchannel->m_direction =m_direction;
		pchannel->m_sensor =m_sensor;
		pchannel->m_index =m_index;
		pchannel->m_highspd=m_highspd;
		pchannel->m_lowspd=m_lowspd;
		pchannel->m_acc =m_acc;
		pchannel->m_dec=m_dec;
		pchannel->m_offset =m_offset;
	}
}

void CHomeConfig::OnBtnOk() 
{
	// TODO: Add your control notification handler code here
	OnDropdownCombo1();
	SaveRecords();
	CMain * main=(CMain *)GetParent();
	ShowWindow(FALSE);
	main->dlgsysparamsel->ShowWindow(TRUE);
}

BOOL CHomeConfig::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	h_SkinDialog.SubClassDialog(m_hWnd);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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