RtListView.cpp
资源名称:PasRTDat.rar [点击查看]
上传用户:shtiemo
上传日期:2017-12-29
资源大小:163k
文件大小:10k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Visual C++
- // RtListView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PasRTDat.h"
- #include "RtListView.h"
- #include "PerDlg.h"
- #include "TimeDlg.h"
- #include "PasRTDatDoc.h"
- #include "SetYCDlg.h"
- #include "SetYXDlg.h"
- #include "RtreeView.h"
- #include "RTDatOpr.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CRtListView
- IMPLEMENT_DYNCREATE(CRtListView, CListView)
- CRtListView::CRtListView()
- {
- gRtuID = 9999;
- }
- CRtListView::~CRtListView()
- {
- }
- BEGIN_MESSAGE_MAP(CRtListView, CListView)
- //{{AFX_MSG_MAP(CRtListView)
- ON_WM_CREATE()
- ON_WM_LBUTTONDBLCLK()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRtListView drawing
- void CRtListView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- }
- CPasRTDatDoc *CRtListView::GetDoc()
- {
- return (CPasRTDatDoc*)GetDocument();
- }
- void CRtListView::InitialList()
- {
- CListCtrl& ListCtrl = GetListCtrl();
- long lStyle;
- lStyle = ListCtrl.SendMessageA(0x1037, 0, 0); // 取扩展风格
- lStyle |= 0x20|0x400|0x1; // 扩展风格--选
- ListCtrl.SendMessageA(0x1036, 0, lStyle); // 设置扩展风格
- /* #define LVS_EX_GRIDLINES 0x00000001
- #define LVS_EX_SUBITEMIMAGES 0x00000002
- #define LVS_EX_CHECKBOXES 0x00000004
- #define LVS_EX_TRACKSELECT 0x00000008
- #define LVS_EX_HEADERDRAGDROP 0x00000010
- #define LVS_EX_FULLROWSELECT 0x00000020 // applies to report mode only
- #define LVS_EX_ONECLICKACTIVATE 0x00000040
- #define LVS_EX_TWOCLICKACTIVATE 0x00000080
- #define LVS_EX_FLATSB 0x00000100
- #define LVS_EX_REGIONAL 0x00000200
- #define LVS_EX_INFOTIP 0x00000400 // listview does InfoTips for you
- #define LVS_EX_UNDERLINEHOT 0x00000800
- #define LVS_EX_UNDERLINECOLD 0x00001000
- #define LVS_EX_MULTIWORKAREAS 0x00002000*/
- }
- /////////////////////////////////////////////////////////////////////////////
- // CRtListView diagnostics
- #ifdef _DEBUG
- void CRtListView::AssertValid() const
- {
- CListView::AssertValid();
- }
- void CRtListView::Dump(CDumpContext& dc) const
- {
- CListView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CRtListView message handlers
- int CRtListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- lpCreateStruct->style |= LVS_REPORT|LVS_SHOWSELALWAYS;
- if (CListView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- GetDoc()->m_pListV = this;
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////
- static CHAR *YCFieldName[4] =
- {
- "RTU名字","遥测点序号","遥测点名称","遥测值"
- };
- ///////////////////////////////////////////////////////////////////////////////
- static CHAR *YXFieldName[4] =
- {
- "RTU名字","遥信点序号","遥信点名称","遥信值"
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int ColumnWidth[4] =
- {
- 106,80,196,100
- };
- //////////////////////////////////////////////////////////////////////////////
- void CRtListView::FillListColumn(CListCtrl& listc,LV_COLUMN lv,char *ColumnName[],int num)
- {
- lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM| LVCF_WIDTH;
- for (int i=0;i<num;i++)
- {
- lv.iSubItem = i;
- lv.pszText = ColumnName[i];
- lv.cx = ColumnWidth[i];
- lv.cchTextMax = 64;
- lv.fmt = LVCFMT_LEFT;
- listc.InsertColumn(i,&lv);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- void CRtListView::FillListYC(int nStart,int nYCYXNum)
- {
- int nFields,i,j;
- float fCoef, fOffSet,YCtmp;
- CString RtuName,strParaName;
- char Name[64],Num[5],YCvalue[20];
- LV_COLUMN lvc;
- LV_ITEM lvi;
- CListCtrl& ListCtrl = GetListCtrl();
- ListCtrl.DeleteAllItems();
- while(ListCtrl.DeleteColumn(0));
- UpdateWindow();
- //int Infonum = YCInfoAry2.GetSize();
- nFields = 4;
- if (nYCYXNum > 0)
- {
- lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM| LVCF_WIDTH;
- FillListColumn(ListCtrl,lvc,YCFieldName,nFields);
- for (i=nStart;i<nYCYXNum+nStart;i++)
- {
- for (j=1;j<=nFields; j++)
- {
- if (j==1)
- {
- lvi.mask = LVIF_TEXT ;
- lvi.iItem = 0;
- lvi.iImage= 2;
- lvi.cchTextMax=64;
- GetRtuName(&(YCInfoAry1[i]->DBID),RtuName,1);
- lvi.pszText = RtuName.GetBuffer(64);
- if (YCInfoAry1[i]->bChanged == 1)
- ListCtrl.InsertItem(i,RtuName.GetBuffer(64),0);
- else
- ListCtrl.InsertItem(i,RtuName.GetBuffer(64),2);
- }
- else
- {
- lvi.mask = LVIF_TEXT ;
- lvi.iItem = i-nStart;
- lvi.cchTextMax=64;
- switch(j)
- {
- case 2:
- sprintf(Num,"%d",i);
- lvi.pszText = Num;
- break;
- case 3:
- if (GetMeaCoef(&(YCInfoAry1[i]->DBID), &fCoef, &fOffSet, strParaName))
- {
- sprintf(Name, strParaName);
- }
- lvi.pszText = Name;
- break;
- case 4:
- YCtmp = YCInfoAry1[i]->fVal*fCoef;
- sprintf(YCvalue,"%f",YCtmp);
- lvi.pszText = YCvalue;
- break;
- }
- lvi.iSubItem = j-1;
- ListCtrl.SetItem(&lvi);
- }
- }
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- void CRtListView::FillListYX(int nStart,int nYCYXNum)
- {
- int nFields,i,j,YXtmp;
- float fCoef, fOffSet;
- CString RtuName,strParaName;
- char Name[64],Num[3],YXstate[3];
- LV_COLUMN lvc;
- LV_ITEM lvi;
- CListCtrl& ListCtrl = GetListCtrl();
- ListCtrl.DeleteAllItems();
- while(ListCtrl.DeleteColumn(0));
- UpdateWindow();
- nFields = 4;
- if (nYCYXNum > 0)
- {
- lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM| LVCF_WIDTH;
- FillListColumn(ListCtrl,lvc,YXFieldName,nFields);
- for (i=nStart;i<nYCYXNum+nStart;i++)
- {
- for (j=1;j<=nFields; j++)
- {
- if (j==1)
- {
- lvi.mask = LVIF_TEXT ;
- lvi.iItem = 0;
- lvi.iImage = 2;
- lvi.cchTextMax=64;
- GetRtuName(&(YXInfoAry1[i]->DBID),RtuName,2);
- lvi.pszText = RtuName.GetBuffer(64);
- if (YXInfoAry1[i]->bChanged == 1)
- ListCtrl.InsertItem(i,RtuName.GetBuffer(64),0);
- else
- ListCtrl.InsertItem(i,RtuName.GetBuffer(64),2);
- }
- else
- {
- lvi.mask = LVIF_TEXT ;
- lvi.iItem =i-nStart;
- lvi.cchTextMax=64;
- switch(j)
- {
- case 2:
- sprintf(Num,"%d",i);
- lvi.pszText = Num;
- break;
- case 3:
- if (GetMeaCoef(&(YXInfoAry1[i]->DBID), &fCoef, &fOffSet, strParaName))
- {
- sprintf(Name, strParaName);
- }
- lvi.pszText = Name;
- break;
- case 4:
- YXtmp = YXInfoAry1[i]->bVal;
- sprintf(YXstate,"%d",YXtmp);
- lvi.pszText = YXstate;
- break;
- }
- lvi.iSubItem = j-1;
- ListCtrl.SetItem(&lvi);
- }
- }
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- void CRtListView::OnInitialUpdate()
- {
- CListView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- CListCtrl& ListCtrl = GetListCtrl();
- m_ImageList.Create(IDB_CHANGE, 16, 1, RGB(255, 255, 255));
- m_ImageList.SetOverlayImage(3, 1);
- ListCtrl.SetImageList(&m_ImageList, LVSIL_SMALL);
- /*long lStyle;
- lStyle = ListCtrl.SendMessageA(0x1037, 0, 0); // 取扩展风格
- lStyle |= 0x20|0x400|0x1; // 扩展风格--选
- ListCtrl.SendMessageA(0x1036, 0, lStyle); // 设置扩展风格
- #define LVS_EX_GRIDLINES 0x00000001
- #define LVS_EX_SUBITEMIMAGES 0x00000002
- #define LVS_EX_CHECKBOXES 0x00000004
- #define LVS_EX_TRACKSELECT 0x00000008
- #define LVS_EX_HEADERDRAGDROP 0x00000010
- #define LVS_EX_FULLROWSELECT 0x00000020 // applies to report mode only
- #define LVS_EX_ONECLICKACTIVATE 0x00000040
- #define LVS_EX_TWOCLICKACTIVATE 0x00000080
- #define LVS_EX_FLATSB 0x00000100
- #define LVS_EX_REGIONAL 0x00000200
- #define LVS_EX_INFOTIP 0x00000400 // listview does InfoTips for you
- #define LVS_EX_UNDERLINEHOT 0x00000800
- #define LVS_EX_UNDERLINECOLD 0x00001000
- #define LVS_EX_MULTIWORKAREAS 0x00002000
- */
- }
- void CRtListView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CListCtrl& ListCtrl = GetListCtrl();
- CRtreeView *pTreeV;
- int i = 0;
- UINT uFlags = 0;
- int cx = 0;
- SetYCDlg SetYCDlg1;
- SetYXDlg SetYXDlg1;
- pTreeV = GetDoc()->m_pTreeV;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- HTREEITEM hTreeItem;
- CString NodeName;
- CTreeCtrl &pTreeCtrl = pTreeV->GetTreeCtrl();
- hTreeItem = pTreeCtrl.GetSelectedItem();
- i = ListCtrl.HitTest(point,&uFlags);
- for (int j=0;j<=2;j++)
- {
- cx = cx+ListCtrl.GetColumnWidth(j);
- }
- if((point.x>cx-10)&&(point.x<cx+ListCtrl.GetColumnWidth(3)+10))
- {
- if (hTreeItem)
- {
- NodeName = pTreeCtrl.GetItemText(hTreeItem);
- }
- if(NodeName=="RTU 遥测一览")
- {
- CString YCname=ListCtrl.GetItemText(i,2);
- CString valuetmp=ListCtrl.GetItemText(i,3);
- float YCvalue=(float)atof(valuetmp.GetBuffer(32));
- SetYCDlg1.m_pListV = this;
- SetYCDlg1.m_YCName = YCname;
- SetYCDlg1.m_OldValue = YCvalue;
- SetYCDlg1.RowIndex = i;
- SetYCDlg1.DoModal();
- }
- else if (NodeName=="RTU 遥信一览")
- {
- CString YXname=ListCtrl.GetItemText(i,2);
- CString Statemp=ListCtrl.GetItemText(i,3);
- BOOL YXstate=(BOOL)atoi(Statemp.GetBuffer(32));
- SetYXDlg1.m_pListV = this;
- SetYXDlg1.m_YXName = YXname;
- SetYXDlg1.m_OldState = YXstate;
- SetYXDlg1.RowIndex = i;
- SetYXDlg1.DoModal();
- }
- }
- CListView::OnLButtonDblClk(nFlags, point);
- }