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

📄 itemadddlg.cpp

📁 modbus编程
💻 CPP
字号:
// ItemAddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DemoClient.h"
#include "ItemAddDlg.h"

#include "MainFrm.h"
#include "DemoClientView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CItemAddDlg dialog


CItemAddDlg::CItemAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CItemAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CItemAddDlg)
	m_strItemName = _T("");
	m_strItemListName = _T("");
	//}}AFX_DATA_INIT
}


void CItemAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CItemAddDlg)
	DDX_Control(pDX, IDC_EDIT_ITEMNAME, m_edItemName);
	DDX_Control(pDX, IDC_ITEMLIST, m_lbItemList);
	DDX_Text(pDX, IDC_EDIT_ITEMNAME, m_strItemName);
	DDV_MaxChars(pDX, m_strItemName, 50);
	DDX_LBString(pDX, IDC_ITEMLIST, m_strItemListName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CItemAddDlg, CDialog)
	//{{AFX_MSG_MAP(CItemAddDlg)
	ON_LBN_SELCHANGE(IDC_ITEMLIST, OnSelchangeItemlist)
	ON_BN_CLICKED(IDADD, OnAdd)
	ON_LBN_DBLCLK(IDC_ITEMLIST, OnDblclkItemlist)
	ON_BN_CLICKED(IDADDALL, OnAddAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CItemAddDlg message handlers

BOOL CItemAddDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CWaitCursor wait;

	UpdateData();

	m_lbItemList.ResetContent();

	int i,nItemCount;
	char buf[100];

	nItemCount = KOC_GetItemCount(m_pView->m_hConnect);

	for (i=0;i<nItemCount;i++)
	{
		KOC_GetItemName(m_pView->m_hConnect,i,buf,100);
		m_lbItemList.AddString(buf);
	}	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CItemAddDlg::OnSelchangeItemlist() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	//m_strItemName = m_strItemListName;
	m_edItemName.SetWindowText(m_strItemListName);

	//UpdateData(FALSE);	
}

void CItemAddDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	m_strItemName.TrimLeft();
	m_strItemName.TrimRight();

	if (m_strItemName.IsEmpty())
	{
		AfxMessageBox("Error ! Item name is empty.");
		return;
	}
	m_pView->AddItem(m_strItemName);
}

void CItemAddDlg::OnDblclkItemlist() 
{
	// TODO: Add your control notification handler code here
	OnAdd();
}

void CItemAddDlg::OnAddAll() 
{
	// TODO: Add your control notification handler code here
	int i,nCount;
	CString strName;
	nCount = m_lbItemList.GetCount();
	for (i=0;i<nCount;i++)
	{
		m_lbItemList.GetText(i,strName);
		m_pView->AddItem(strName);
	}
}

⌨️ 快捷键说明

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