📄 viewpara.cpp
字号:
// ViewPara.cpp : implementation file
//
#include "stdafx.h"
#include "3104C.h"
#include "ViewPara.h"
#include "mydata.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewPara dialog
#define ListColumnNum 9
//#define ListRowNum 64*2
static _TCHAR *_ColumnLabel[ListColumnNum] =
{
_T("通道号"),_T("通道名称"),_T("接收通道类型"),_T("接收通道参数"),_T("对端IP"),_T("收/发字节数"),_T("发送通道类型"),_T("发送通道参数"),_T("收/发字节数"),
};
CViewPara::CViewPara(CWnd* pParent /*=NULL*/)
: CDialog(CViewPara::IDD, pParent)
{
//{{AFX_DATA_INIT(CViewPara)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CViewPara::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CViewPara)
DDX_Control(pDX, IDC_LIST_PARA, m_ListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CViewPara, CDialog)
//{{AFX_MSG_MAP(CViewPara)
ON_BN_CLICKED(ID_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewPara message handlers
CString GetChanPara(DEVPARA *dev)
{
if(dev == NULL) return "";
CString str,str1;
if(dev->Type == COM)
{
str.Format("%s,%d,",dev->devName,dev->Baud);
if(dev->CheckBit == 0) str1 = "无";
else if(dev->CheckBit == 1) str1 = "奇";
else if(dev->CheckBit ==2) str1 = "偶";
str += str1;
str1.Format(",%d,%d",dev->DataBit ,dev->StopBit);
str+=str1;
}
else if(dev->Type == TCPRTU || dev->Type == UDPRTU)
str .Format("%s",dev->devName);
else
str = "错误";
return str;
}
BOOL CViewPara::OnInitDialog()
{
CDialog::OnInitDialog();
int ListRowNum;
ListRowNum = G_Channel.chan_num;
// TODO: Add extra initialization here
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/
LVS_EX_HEADERDRAGDROP );
CString str;
int i;
LV_COLUMN lvc;
int ListWith = 90;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
for(i = 0; i<ListColumnNum; i++)
{
lvc.iSubItem = i;
lvc.pszText = _ColumnLabel[i];
if(i==0) lvc.cx = 60;
else if(i==3 || i==7) lvc.cx = 160;
else lvc.cx = ListWith;
lvc.fmt = LVCFMT_CENTER;
m_ListCtrl.InsertColumn(i,&lvc);
}
LV_ITEM lvi;
char m_str[2];
for(i = 0; i < ListRowNum; i++)
{
str.Format("%02d",i);
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
lvi.iItem = i;
lvi.iSubItem = 0;
strcpy(m_str,str);
lvi.pszText = m_str;//[0];
lvi.iImage = i;
lvi.stateMask = LVIS_STATEIMAGEMASK;
lvi.state = INDEXTOSTATEIMAGEMASK(1);
m_ListCtrl.InsertItem(&lvi);
m_ListCtrl.SetItemText(i, 1, G_Channel.chan_data[i].chanName);
if(G_Channel.chan_data[i].rchanpara.Type==COM) str = "RS232";
else if(G_Channel.chan_data[i].rchanpara.Type==TCPRTU) str = "TCP";
else if(G_Channel.chan_data[i].rchanpara.Type==UDPRTU) str = "UDP";
else str = "未知";
m_ListCtrl.SetItemText(i, 2, str);
str = GetChanPara(&G_Channel.chan_data[i].rchanpara);
m_ListCtrl.SetItemText(i, 3, str);
str.Format("%s", inet_ntoa(G_Channel.chan_data[i].addr));
m_ListCtrl.SetItemText(i, 4, str);
str.Format("%d/%d", G_Channel.chan_data[i].rchanpara.RecCnt, G_Channel.chan_data[i].rchanpara.SendCnt);
m_ListCtrl.SetItemText(i, 5, str);
if(G_Channel.chan_data[i].tchanpara.Type==COM) str = "RS232";
else if(G_Channel.chan_data[i].tchanpara.Type==TCPRTU) str = "TCP";
else if(G_Channel.chan_data[i].tchanpara.Type==UDPRTU) str = "UDP";
else str = "未知";
m_ListCtrl.SetItemText(i, 6, str);
str = GetChanPara(&G_Channel.chan_data[i].tchanpara);
m_ListCtrl.SetItemText(i, 7, str);
str.Format("%d/%d", G_Channel.chan_data[i].tchanpara.RecCnt, G_Channel.chan_data[i].tchanpara.SendCnt);
m_ListCtrl.SetItemText(i, 8, str);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CViewPara::OnUpdate()
{
// TODO: Add your control notification handler code here
int ListRowNum;
CString str;
ListRowNum = G_Channel.chan_num;
for(int i = 0; i < ListRowNum; i++)
{
m_ListCtrl.SetItemText(i, 1, G_Channel.chan_data[i].chanName);
if(G_Channel.chan_data[i].rchanpara.Type==0) str = "RS232";
else if(G_Channel.chan_data[i].rchanpara.Type==1) str = "TCP";
else if(G_Channel.chan_data[i].rchanpara.Type==2) str = "UDP";
else str = "未知";
m_ListCtrl.SetItemText(i, 2, str);
str = GetChanPara(&G_Channel.chan_data[i].rchanpara);
m_ListCtrl.SetItemText(i, 3, str);
str.Format("%s", inet_ntoa(G_Channel.chan_data[i].addr));
m_ListCtrl.SetItemText(i, 4, str);
str.Format("%d/%d", G_Channel.chan_data[i].rchanpara.RecCnt, G_Channel.chan_data[i].rchanpara.SendCnt);
m_ListCtrl.SetItemText(i, 5, str);
if(G_Channel.chan_data[i].tchanpara.Type==0) str = "RS232";
else if(G_Channel.chan_data[i].tchanpara.Type==1) str = "TCP";
else if(G_Channel.chan_data[i].tchanpara.Type==2) str = "UDP";
else str = "未知";
m_ListCtrl.SetItemText(i, 6, str);
str = GetChanPara(&G_Channel.chan_data[i].tchanpara);
m_ListCtrl.SetItemText(i, 7, str);
str.Format("%d/%d", G_Channel.chan_data[i].tchanpara.RecCnt, G_Channel.chan_data[i].tchanpara.SendCnt);
m_ListCtrl.SetItemText(i, 8, str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -