📄 datanodeview.cpp
字号:
// ListView.cpp : implementation file
//
#include "stdafx.h"
#include "WorkSpace.h"
//#include "ProjectItem.h"
#include "DataNodeDoc.h"
#include "DataNodeView.h"
//#include "WorkSpaceBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDataNodeView
IMPLEMENT_DYNCREATE(CDataNodeView, CListView)
CDataNodeView::CDataNodeView()
{
}
CDataNodeView::~CDataNodeView()
{
}
BEGIN_MESSAGE_MAP(CDataNodeView, CListView)
//{{AFX_MSG_MAP(CDataNodeView)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDataNodeView message handlers
int CDataNodeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// Initialize the document object's pointer
// to the list view object.
GetDocument()->m_pListView = this;
// TODO: Add your specialized creation code here
DWORD dwStyle = SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;
SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)dwStyle);
return 0;
}
#if 0
void CDataNodeView::DisplayTypeInfo(const HTREEITEM ParentNode)
{
static char * headers[] = { "Animal", NULL };
DisplayChildren(headers, ParentNode);
}
void CDataNodeView::DisplayClassInfo(const HTREEITEM ParentNode)
{
static char * headers[] = { "Types", NULL };
DisplayChildren(headers, ParentNode);
}
void CDataNodeView::DisplayChildren(char **headers, const HTREEITEM ParentNode)
{
CListCtrl & clc = GetListCtrl();
CTreeCtrl & ctc = GetDocument()->m_pTreeView->GetTreeCtrl();
int i = 0;
LV_COLUMN lv;
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lv.fmt = LVCFMT_LEFT;
EraseList();
while (headers[i])
{
lv.cx = 15 * clc.GetStringWidth(headers[i]) / 10;
lv.pszText = headers[i];
clc.InsertColumn(i++, &lv);
lv.fmt = LVCFMT_CENTER;
}
HTREEITEM node = ctc.GetChildItem(ParentNode);
i = 0;
CString s;
while (node != NULL)
{
s = ctc.GetItemText(node);
clc.InsertItem(i++, s);
node = ctc.GetNextItem(node, TVGN_NEXT);
}
}
void CDataNodeView::DisplayAnimalInfo(const DWORD itemData)
{
static char * headers[] = { "Type", "Animal",
"Max. Weight (kgs)", NULL };
int i = 0;
LV_COLUMN lv;
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lv.fmt = LVCFMT_LEFT;
CListCtrl & clc = GetListCtrl();
EraseList();
while (headers[i])
{
lv.cx = 15 * clc.GetStringWidth(headers[i]) / 10;
lv.pszText = headers[i];
clc.InsertColumn(i++, &lv);
lv.fmt = LVCFMT_CENTER;
}
CProjectItem & prjItem =
GetDocument()->m_ProjectList.GetAt((POSITION)itemData);
// Insert the 3 pieces of information and expand
// column widths as necessary.
clc.InsertItem(0, prjItem.m_type);
int w = clc.GetStringWidth(prjItem.m_type);
if ( w > clc.GetColumnWidth(0) )
clc.SetColumnWidth(0, 15 * w / 10);
clc.SetItemText(0, 1, prjItem.m_animal);
w = clc.GetStringWidth(prjItem.m_animal);
if ( clc.GetColumnWidth(1) - 10 < w )
clc.SetColumnWidth(1, 17 * w / 10);
CString weight;
weight.Format("%d", prjItem.m_weight);
clc.SetItemText(0, 2, weight);
w = clc.GetStringWidth(weight);
if ( clc.GetColumnWidth(1) - 10 < w )
clc.SetColumnWidth(1, 17 * w / 10);
}
#endif
void CDataNodeView::DeviceNodeSerialInstaller(/*const HTREEITEM*/)
{
}
void CDataNodeView::DeviceNodeNetworkInstaller(/*const HTREEITEM*/)
{
}
void CDataNodeView::DeviceNodeControllerInstaller(/*const HTREEITEM*/)
{
}
void CDataNodeView::DeviceNodeOPCServerInstaller(/*const HTREEITEM*/)
{
}
void CDataNodeView::DeviceNodeDDEInstaller(/*const HTREEITEM*/)
{
}
void CDataNodeView::DataNodeGeneralBuilder(/*const HTREEITEM*/)
{
CListCtrl & clc = GetListCtrl();
// CTreeCtrl & ctc = GetDocument()->m_pTreeView->GetTreeCtrl();
int i = 0;
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
// lvc.mask=LVCF_FMT|LVCF_TEXT|LVCF_SUBITEM|LVCF_WIDTH;
lvc.iSubItem=0;
lvc.cx = 0;
EraseList();
CString s;
//while (headers[i])
for( i = IDS_VARIABLE_IDENTIFIER; i <= IDS_VARIABLE_ATTRIBUTE; i++)
{
s.LoadString(i);
//lvc.cx = 15 * clc.GetStringWidth(s.G(headers[i]) / 10;
lvc.cx += 50;
//lvc.cx = s.GetLength();
lvc.pszText = s.GetBuffer(s.GetLength());
//lstrcpyn(lvc.pszText, s.GetBuffer(s.GetLength()) , s.GetLength());
clc.InsertColumn(lvc.iSubItem, &lvc);
lvc.iSubItem++;
lvc.fmt = LVCFMT_CENTER;
}
}
void CDataNodeView::DataNodeRecipeBuilder(/*const HTREEITEM*/)
{
}
void CDataNodeView::DataNodeAlarmBuilder(/*const HTREEITEM*/)
{
}
void CDataNodeView::EnviromentForDrawing(/*const HTREEITEM*/)
{
}
void CDataNodeView::EnviromentForRuntime(/*const HTREEITEM*/)
{
}
void CDataNodeView::OnInitialUpdate()
{
// GetListCtrl().ModifyStyle(NULL, LVS_REPORT);
CListView::OnInitialUpdate();
DataNodeGeneralBuilder();
}
BOOL CDataNodeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style |= LVS_REPORT |
LVS_SHOWSELALWAYS |
LVS_SINGLESEL;
return CListView::PreCreateWindow(cs);
}
void CDataNodeView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
void CDataNodeView::EraseList()
{
CListCtrl& ctlList = GetListCtrl();
// Remove all the list's data.
ctlList.DeleteAllItems();
// Remove all the columns and consequently their headers.
while(ctlList.DeleteColumn(0));
// Force a repaint.
UpdateWindow();
}
/////////////////////////////////////////////////////////////////////////////
// CDataNodeView diagnostics
#ifdef _DEBUG
void CDataNodeView::AssertValid() const
{
CListView::AssertValid();
}
void CDataNodeView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CWorkspaceDoc* CDataNodeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWorkspaceDoc)));
return (CWorkspaceDoc*)m_pDocument;
}
#endif //_DEBUG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -