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

📄 proppage.cpp

📁 VC6++ program demo source for communication with PLC to read and write data.
💻 CPP
字号:
// PropPage.cpp : implementation file
//

#include "stdafx.h"
#include "LinkPLC.h"
#include "PropPage.h"
#include <afx.h>

#include "setting.h"
#include "comm1.h"
#include "Config.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CPropPage1 property page

IMPLEMENT_DYNCREATE(CPropPage1, CPropertyPage)

CPropPage1::CPropPage1() : CPropertyPage(CPropPage1::IDD)
{
	//{{AFX_DATA_INIT(CPropPage1)
	//}}AFX_DATA_INIT

	for (int i=0 ; i<100 ; i++)
	{
		mValue[i]=new char[4];
		strset(mValue[i],'\0');

	}

}

CPropPage1::~CPropPage1()
{
}

void CPropPage1::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropPage1)
	DDX_Control(pDX, IDC_LIST1, m_ProgList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropPage1, CPropertyPage)
	//{{AFX_MSG_MAP(CPropPage1)
	ON_BN_CLICKED(IDC_CONFIG, OnConfig)
	ON_BN_CLICKED(IDC_FILENAME, OnFilename)
	ON_WM_SHOWWINDOW()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropPage1 message handlers
BOOL CPropPage1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
		CRect rect;
		m_ProgList.GetClientRect(rect);

		LV_COLUMN		lvcolumn;

		lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
		lvcolumn.fmt = LVCFMT_LEFT;

		lvcolumn.pszText =  "Data";
		lvcolumn.iSubItem = 0;
		lvcolumn.cx = 100;  // SubItem is twice as large
		m_ProgList.InsertColumn(0, &lvcolumn);  // assumes return value is OK.

		lvcolumn.pszText =  "Label";
		lvcolumn.iSubItem = 0;
		lvcolumn.cx = rect.Width()-100;  // SubItem is twice as large
		m_ProgList.InsertColumn(0, &lvcolumn);  // assumes return value is OK.
		m_ProgList.SetBkColor(RGB(50,50,100));
		m_ProgList.SetTextBkColor(RGB(50,50,100));
		m_ProgList.SetTextColor(RGB(255,255,255));

		ItemUpdate();
		mBmGreen.LoadBitmap(IDB_BMGREEN);
		mBmGray.LoadBitmap(IDB_BMGRAY);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CPropPage1::OnConfig() 
{
	// TODO: Add your control notification handler code here
	CConfig dlgSetData;

	KillTimer(1);

	dlgSetData.mItemCount=mItemCount;
	for (int i=0 ; i<mItemCount ; i++)
		dlgSetData.mDevice[i]=mDevice[i];
	for (i=0 ; i<mItemCount ; i++)
		dlgSetData.mComment[i]=mComment[i];

	if(dlgSetData.DoModal()==IDOK)
	{
		mItemCount=dlgSetData.mItemCount;
		for (int i=0 ; i<mItemCount ; i++)
			mDevice[i]=dlgSetData.mDevice[i];
		for (i=0 ; i<mItemCount ; i++)
			mComment[i]=dlgSetData.mComment[i];
		
		ItemUpdate();

		GetParent()->GetParent()->GetParent()->PostMessage(WM_FILEUPDATE,2,3);
	}

		SetTimer(1,100,NULL);

}

void CPropPage1::OnFilename() 
{
	// TODO: Add your control notification handler code here
UINT wt=	WinExec("C:\\Program Files\\Microsoft Office\\Office\\Msaccess.exe",SW_MAXIMIZE);
}
void CPropPage1::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	ItemUpdate();
	CPropertyPage::OnShowWindow(bShow, nStatus);
}

void CPropPage1::ItemUpdate()
{
	m_ProgList.DeleteAllItems();
	for(int i=0 ; i<mItemCount ; i++)
	{
		m_ProgList.InsertItem(i,mComment[i]);
		m_ProgList.SetItemText(i,1,mDevice[i]);
		m_ProgList.SetItemText(i,1,mValue[i]);
	}
}

void CPropPage1::XLedUpdate(char *lpStatus)
{
	CStatic* st;


	for(int i=0 ; i<24 ; i++)
	{
		st=(CStatic *) GetDlgItem(IDC_X0+i);
				if(lpStatus[i+5]=='1')
			st->SetBitmap(mBmGreen);
		else
			st->SetBitmap(mBmGray);
	}

}


void CPropPage1::YLedUpdate(char *lpStatus)
{
	CStatic* st;

	for(int i=0 ; i<16 ; i++)
	{
		st=(CStatic *) GetDlgItem(IDC_Y0+i);
		if(lpStatus[i+5]=='1')
			st->SetBitmap(mBmGreen);
		else
			st->SetBitmap(mBmGray);
	}
}


void CPropPage1::RLedUpdate(char *lpStatus)
{
	CStatic* st;
	//RUN
	st=(CStatic *) GetDlgItem(IDC_RUN);
	if(lpStatus[5]=='1')
	{
		st->SetBitmap(mBmGreen);
	
	}
	else
		st->SetBitmap(mBmGray);
}

void CPropPage1::OnDestroy() 
{
	GetParent()->GetParent()->GetParent()->GetParent()->PostMessage(WM_CLOSE, 0, 0);
	CPropertyPage::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

void CPropPage1::OnExit() 
{
	// TODO: Add your control notification handler code here
GetParent()->GetParent()->GetParent()->GetParent()->PostMessage(WM_CLOSE, 0, 0);	
}

⌨️ 快捷键说明

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