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

📄 dlgsetcom.cpp

📁 使用vc++技术实现光电机串口通信管理程序
💻 CPP
字号:
// DlgSetCom.cpp : implementation file
//

#include "stdafx.h"
#include "pcm120.h"
#include "DlgSetCom.h"
#include "DlgAllStaSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgSetCom dialog


CDlgSetCom::CDlgSetCom(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSetCom::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSetCom)
	//}}AFX_DATA_INIT
}


void CDlgSetCom::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSetCom)
	DDX_Control(pDX, IDC_LIST_COM, m_Listcom);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSetCom, CDialog)
	//{{AFX_MSG_MAP(CDlgSetCom)
	ON_NOTIFY(NM_CLICK, IDC_LIST_COM, OnClickListCom)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSetCom message handlers

void CDlgSetCom::OnOK() 
{
	// TODO: Add extra validation here
	char chID[10],chCom[10];
		CString strPath,strConf;
	CDlgAllStaSet dlgallstaset;
	dlgallstaset.GetModulePath(strPath,NULL);
	strConf=strPath+"config.ini";
	for(int i=0;i<m_Listcom.GetItemCount();i++)
	{
		m_Listcom.GetItemText(i,0,chID,10);
		m_Listcom.GetItemText(i,1,chCom,2);
		WritePrivateProfileString("Com",chID,chCom,strConf);
		
	}
	
	CDialog::OnOK();	


}

BOOL CDlgSetCom::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
		LV_COLUMN lvc;	
		lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
		
		lvc.fmt = LVCFMT_LEFT;
		lvc.cx = 80;
		lvc.iSubItem = 0;
		lvc.pszText = "设备ID";
		m_Listcom.InsertColumn(0,&lvc);
		lvc.iSubItem = 1;
		lvc.pszText = "使用串口号";
		m_Listcom.InsertColumn(1,&lvc);
	DWORD dwStyle =m_Listcom.GetExtendedStyle();
	m_Listcom.SetExtendedStyle(dwStyle|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_TWOCLICKACTIVATE );
	CString strPath,strConf;
	CDlgAllStaSet dlgallstaset;
	dlgallstaset.GetModulePath(strPath,NULL);
	strConf=strPath+"config.ini";
	strPath += "PCM120networksetup.ini";
	
	char chGet[10],chGetCom[10];
	GetPrivateProfileString("general","StationCnt","1",chGet,10,strPath);
	int nSta;
	nSta=atoi(chGet);
	for(int i=0;i<nSta;i++)
	{
		CString strSect;
		strSect.Format("station%d",i+1);
		GetPrivateProfileString(strSect,"DevCnt","1",chGet,10,strPath);
		int nDev;
		nDev=atoi(chGet);
		for(int m=0;m<nDev;m++)
		{
			CString strSectID;
			strSectID.Format("第%d个设备ID",m+1);
			GetPrivateProfileString(strSect,strSectID,"1",chGet,10,strPath);
			GetPrivateProfileString("Com",chGet,"1",chGetCom,10,strConf);
			
			int n=m_Listcom.InsertItem(0,chGet);
			m_Listcom.SetItemText(n,1,chGetCom);
		}
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgSetCom::OnClickListCom(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	for(int i=0;i<m_Listcom.GetItemCount();i++)
	{
		if(m_Listcom.GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED)
		{
			CString strtemp;
			char chget[2];
			m_Listcom.GetItemText(i,1,chget,2);
			int nGet=atoi(chget);
			switch(nGet) {
			case 1:
				m_Listcom.SetItemText(i,1,"2");
				break;
			case 2:
				m_Listcom.SetItemText(i,1,"3");
				break;
			case 3:
				m_Listcom.SetItemText(i,1,"4");
				break;
			case 4:
				m_Listcom.SetItemText(i,1,"1");
				break;
			
			}
			
		}
		
		
	}
	
	*pResult = 0;
}

⌨️ 快捷键说明

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