📄 dostatusview.cpp
字号:
// DOStatusView.cpp : implementation file
//
#include "stdafx.h"
#include "mbpc.h"
#include "DOStatusView.h"
#include "OnOffDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDOStatusView
IMPLEMENT_DYNCREATE(CDOStatusView, CFormView)
CDOStatusView::CDOStatusView()
: CFormView(CDOStatusView::IDD)
{
//{{AFX_DATA_INIT(CDOStatusView)
m_nTimerFlag = 0;
//}}AFX_DATA_INIT
}
CDOStatusView::~CDOStatusView()
{
}
void CDOStatusView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDOStatusView)
DDX_Control(pDX, IDC_LISTENABLE, m_ListEnable);
DDX_Control(pDX, IDC_LISTDI, m_ListDI);
DDX_Control(pDX, IDC_LISTDO, m_ListDO);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDOStatusView, CFormView)
//{{AFX_MSG_MAP(CDOStatusView)
ON_NOTIFY(NM_CLICK, IDC_LISTDO, OnClickDOList)
ON_WM_CREATE()
ON_WM_TIMER()
ON_NOTIFY(NM_CLICK, IDC_LISTENABLE, OnClickListenable)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDOStatusView diagnostics
#ifdef _DEBUG
void CDOStatusView::AssertValid() const
{
CFormView::AssertValid();
}
void CDOStatusView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDOStatusView message handlers
void CDOStatusView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
char buf[16];
LONG lStyle;
int i;
m_ListDO.DeleteAllItems();
m_ListDI.DeleteAllItems();
m_ListEnable.DeleteAllItems();
for(i = 0; i < 3; i++)
{
m_ListEnable.DeleteColumn(0);
m_ListDI.DeleteColumn(0);
m_ListDO.DeleteColumn(0);
}
lStyle = GetWindowLong(m_ListDO.m_hWnd, GWL_STYLE);//获取当前窗口style
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle |= LVS_REPORT; //设置style
SetWindowLong(m_ListDO.m_hWnd, GWL_STYLE, lStyle);//设置style
SetWindowLong(m_ListDI.m_hWnd, GWL_STYLE, lStyle);//设置style
SetWindowLong(m_ListEnable.m_hWnd, GWL_STYLE, lStyle);//设置style
DWORD dwStyle = m_ListDO.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
m_ListDO.SetExtendedStyle(dwStyle); //设置扩展风格
m_ListDI.SetExtendedStyle(dwStyle);
m_ListEnable.SetExtendedStyle(dwStyle);
m_ListDO.InsertColumn(0,"ID",LVCFMT_CENTER,40);
m_ListDO.InsertColumn(1,"名称",LVCFMT_CENTER,120);
m_ListDO.InsertColumn(2,"状态",LVCFMT_CENTER,80);
m_ListDI.InsertColumn(0,"ID",LVCFMT_CENTER,40);
m_ListDI.InsertColumn(1,"名称",LVCFMT_CENTER,120);
m_ListDI.InsertColumn(2,"状态",LVCFMT_CENTER,80);
m_ListEnable.InsertColumn(0,"ID",LVCFMT_CENTER,40);
m_ListEnable.InsertColumn(1,"名称",LVCFMT_CENTER,120);
m_ListEnable.InsertColumn(2,"状态",LVCFMT_CENTER,80);
if(GetDocument()->m_bSetuped)
{
for(i = 0; i < GetDocument()->m_device_info.do_count; i++)
{
CString str;
str.Format("%d",i + 1);
int nRow = m_ListDO.InsertItem(i,str);
memset(buf,0,16);
memcpy(&buf,GetDocument()->m_DoInfo[i].digital_name,12);
m_ListDO.SetItemText(nRow,1,buf);
}
for(int j = 0; j < GetDocument()->m_device_info.di_count; j++)
{
CString str;
str.Format("%d",j + 1);
int nRow = m_ListDI.InsertItem(j,str);
memset(buf,0,16);
memcpy(&buf,GetDocument()->m_DiInfo[j].digital_name,12);
m_ListDI.SetItemText(nRow,1,buf);
}
for(int k = 0; k < GetDocument()->m_device_info.enable_count; k++)
{
CString str;
str.Format("%d",k + 1);
int nRow = m_ListEnable.InsertItem(k,str);
memset(buf,0,16);
memcpy(&buf,GetDocument()->m_EnableInfo[k].digital_name,12);
m_ListEnable.SetItemText(nRow,1,buf);
}
for(int z = 0; z < GetDocument()->m_device_info.do_count; z++)
{
if(GetDocument()->m_bDoStatus[z] == 0)
{
m_ListDO.SetItemText(z,2,(CString)GetDocument()->m_DoInfo[z].off_name);
}
else
{
m_ListDO.SetItemText(z,2,(CString)GetDocument()->m_DoInfo[z].on_name);
}
}//开出
for(int x = 0; x < GetDocument()->m_device_info.di_count; x++)
{
if(GetDocument()->m_bDistatus[x] == 0)
{
m_ListDI.SetItemText(x,2,(CString)GetDocument()->m_DiInfo[x].off_name);
}
else
{
m_ListDI.SetItemText(x,2,(CString)GetDocument()->m_DiInfo[x].on_name);
}
}//开入
for(int y = 0; y < GetDocument()->m_device_info.enable_count; y++)
{
if(GetDocument()->m_bEnableStatus[y] == 0)
{
m_ListEnable.SetItemText(y,2,(CString)GetDocument()->m_EnableInfo[y].off_name);
}
else
{
m_ListEnable.SetItemText(y,2,(CString)GetDocument()->m_EnableInfo[y].on_name);
}
}//压板
}
}
void CDOStatusView::OnClickDOList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem != -1)
{
if(pNMListView->iSubItem == 2)
{
COnOffDlg dlg;
dlg.m_szTitle.Format("%s", GetDocument()->m_DoInfo[pNMListView->iItem].digital_name);
dlg.m_bOnOff = GetDocument()->m_bDoStatus[pNMListView->iItem];
UpdateData(FALSE);
if(dlg.DoModal() == IDOK)
{
GetDocument()->OperateDo(pNMListView->iItem,dlg.m_bOnOff);
}
}
// CString strtemp;
// strtemp.Format("单击的是第%d行第%d列",
// pNMListView->iItem, pNMListView->iSubItem);
// AfxMessageBox(strtemp);
}
*pResult = 0;
}
CMbpcDoc* CDOStatusView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMbpcDoc)));
return (CMbpcDoc*)m_pDocument;
}
int CDOStatusView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,100,NULL);
return 0;
}
void CDOStatusView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(1 == nIDEvent)
{
m_nTimerFlag++;
if(m_nTimerFlag > 1)
{
m_nTimerFlag --;
}
else
{
if(GetDocument()->m_bSetuped)
{
if(GetDocument()->m_bSwitch)
{
for(int i = 0; i < GetDocument()->m_device_info.do_count; i++)
{
if(GetDocument()->m_bDoStatus[i] == 0)
{
m_ListDO.SetItemText(i,2,(CString)GetDocument()->m_DoInfo[i].off_name);
}
else
{
m_ListDO.SetItemText(i,2,(CString)GetDocument()->m_DoInfo[i].on_name);
}
}//开出
for(int j = 0; j < GetDocument()->m_device_info.di_count; j++)
{
if(GetDocument()->m_bDistatus[j] == 0)
{
m_ListDI.SetItemText(j,2,(CString)GetDocument()->m_DiInfo[j].off_name);
}
else
{
m_ListDI.SetItemText(j,2,(CString)GetDocument()->m_DiInfo[j].on_name);
}
}//开入
for(int k = 0; k < GetDocument()->m_device_info.enable_count; k++)
{
if(GetDocument()->m_bEnableStatus[k] == 0)
{
m_ListEnable.SetItemText(k,2,(CString)GetDocument()->m_EnableInfo[k].off_name);
}
else
{
m_ListEnable.SetItemText(k,2,(CString)GetDocument()->m_EnableInfo[k].on_name);
}
}//压板
GetDocument()->m_bSwitch = 0;
}
}
}
m_nTimerFlag--;
}
CFormView::OnTimer(nIDEvent);
}
void CDOStatusView::OnClickListenable(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem != -1)
{
if(pNMListView->iSubItem == 2)
{
COnOffDlg dlg;
dlg.m_szTitle.Format("%s", this->GetDocument()->m_EnableInfo[pNMListView->iItem].digital_name);
if(GetDocument()->m_bEnableStatus[pNMListView->iItem] == 0)
dlg.m_bOnOff = FALSE;
else
dlg.m_bOnOff = TRUE;
//dlg.m_bOnOff = GetDocument()->m_bEnableStatus[pNMListView->iItem];
UpdateData(FALSE);
if(dlg.DoModal() == IDOK)
{
GetDocument()->OperateEnable(pNMListView->iItem,dlg.m_bOnOff);
}
}
}
*pResult = 0;
}
void CDOStatusView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// TODO: Add your specialized code here and/or call the base class
UpdateData();
if(bActivate == FALSE)
{
KillTimer(1);
}
else
{
OnInitialUpdate();
SetTimer(1,500,NULL);
}
CFormView::Invalidate();
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CDOStatusView::OnDestroy()
{
CFormView::OnDestroy();
// TODO: Add your message handler code here
KillTimer(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -